From a9279072c15a680df63c73f58b500a6b481fd7d6 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 27 Jul 2018 21:15:57 -0400 Subject: [PATCH] Autocreate velocity.toml --- .../com/velocitypowered/proxy/VelocityServer.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 09e0f4b0b..2019714e7 100644 --- a/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -13,7 +13,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.IOException; -import java.net.InetSocketAddress; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; import java.nio.file.Paths; import java.security.KeyPair; @@ -48,7 +50,15 @@ public class VelocityServer { // Create a key pair logger.info("Booting up Velocity..."); try { - configuration = VelocityConfiguration.read(Paths.get("velocity.toml")); + Path configPath = Paths.get("velocity.toml"); + try { + configuration = VelocityConfiguration.read(configPath); + } catch (NoSuchFileException e) { + logger.info("No velocity.toml found, creating one for you..."); + Files.copy(VelocityServer.class.getResourceAsStream("/velocity.toml"), configPath); + configuration = VelocityConfiguration.read(configPath); + } + if (!configuration.validate()) { logger.error("Your configuration is invalid. Velocity will refuse to start up until the errors are resolved."); System.exit(1);