From 428a4435f111ab6ac3bcf06c1b5d482b62196364 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Mon, 9 May 2022 20:09:00 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9C=20simple=20server=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/lixou/stracciatella/ServerConfig.kt | 9 +++++++++ .../cc/lixou/stracciatella/Stracciatella.kt | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/cc/lixou/stracciatella/ServerConfig.kt diff --git a/src/main/kotlin/cc/lixou/stracciatella/ServerConfig.kt b/src/main/kotlin/cc/lixou/stracciatella/ServerConfig.kt new file mode 100644 index 0000000..e1aad48 --- /dev/null +++ b/src/main/kotlin/cc/lixou/stracciatella/ServerConfig.kt @@ -0,0 +1,9 @@ +package cc.lixou.stracciatella + +import kotlinx.serialization.Serializable + +@Serializable +data class ServerConfig( + @Serializable + var port: Int = 25565 +) \ No newline at end of file diff --git a/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt b/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt index 5ead7a8..56bbfbc 100644 --- a/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt +++ b/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt @@ -1,17 +1,32 @@ package cc.lixou.stracciatella +import cc.lixou.stracciatella.config.Config import cc.lixou.stracciatella.game.GameManager import net.minestom.server.MinecraftServer import net.minestom.server.coordinate.Pos import net.minestom.server.event.player.PlayerDisconnectEvent import net.minestom.server.event.player.PlayerLoginEvent import net.minestom.server.instance.block.Block +import org.slf4j.LoggerFactory +import java.nio.file.Path class Stracciatella { private val server = MinecraftServer.init() + private val LOGGER = LoggerFactory.getLogger(Stracciatella::class.java) + + var config = ServerConfig() + private set + init { + // region [Server Config] + LOGGER.info("Loading Configuration (stracciatella.yml)") + config = ServerConfig() + config = Config.loadConfig(Path.of("stracciatella.yml"), config) + // endregion + + val eventHandler = MinecraftServer.getGlobalEventHandler() eventHandler.addListener(PlayerDisconnectEvent::class.java) { event -> GameManager.unregisterPlayer(event.player) @@ -36,7 +51,8 @@ class Stracciatella { } fun start() { - server.start("0.0.0.0", 25565) + LOGGER.info("Starting Stracciatella on Port ${config.port}") + server.start("0.0.0.0", config.port) } } \ No newline at end of file