diff --git a/src/main/java/cc/reconnected/server/RccServer.java b/src/main/java/cc/reconnected/server/RccServer.java index d61e31b..c13a353 100644 --- a/src/main/java/cc/reconnected/server/RccServer.java +++ b/src/main/java/cc/reconnected/server/RccServer.java @@ -45,6 +45,7 @@ import net.minecraft.util.WorldSavePath; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.util.Date; @@ -52,7 +53,7 @@ public class RccServer implements ModInitializer { public static final String MOD_ID = "rcc-server"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); - public static Config CONFIG = ConfigManager.load(); + public static Config CONFIG; public static final StateManager state = new StateManager(); @@ -62,10 +63,6 @@ public class RccServer implements ModInitializer { return INSTANCE; } - public RccServer() { - INSTANCE = this; - } - private LuckPerms luckPerms; public LuckPerms luckPerms() { @@ -87,10 +84,21 @@ public class RccServer implements ModInitializer { public static final RegistryKey CHAT_TYPE = RegistryKey.of(RegistryKeys.MESSAGE_TYPE, new Identifier(MOD_ID, "chat")); private static boolean warnedAboutUnsignedMessages = false; + public RccServer() { + INSTANCE = this; + } + @Override public void onInitialize() { LOGGER.info("Starting rcc-server"); + try { + CONFIG = ConfigManager.load(); + } catch (Exception e) { + LOGGER.error("Failed to load config. Refusing to continue.", e); + return; + } + ServerLifecycleEvents.SERVER_STARTING.register(server -> { RccServer.server = server; state.register(server.getSavePath(WorldSavePath.ROOT).resolve("data").resolve(RccServer.MOD_ID)); diff --git a/src/main/java/cc/reconnected/server/commands/admin/RccCommand.java b/src/main/java/cc/reconnected/server/commands/admin/RccCommand.java index e2724b8..5dbde8d 100644 --- a/src/main/java/cc/reconnected/server/commands/admin/RccCommand.java +++ b/src/main/java/cc/reconnected/server/commands/admin/RccCommand.java @@ -8,6 +8,8 @@ import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; +import java.io.IOException; + import static net.minecraft.server.command.CommandManager.literal; public class RccCommand { diff --git a/src/main/java/cc/reconnected/server/config/ConfigManager.java b/src/main/java/cc/reconnected/server/config/ConfigManager.java index dd0c9d7..7f1e29b 100644 --- a/src/main/java/cc/reconnected/server/config/ConfigManager.java +++ b/src/main/java/cc/reconnected/server/config/ConfigManager.java @@ -8,6 +8,7 @@ import net.fabricmc.loader.api.FabricLoader; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; @@ -20,18 +21,16 @@ public class ConfigManager { private static final Path configFilePath = FabricLoader.getInstance().getConfigDir().resolve(RccServer.MOD_ID + ".json"); private static Config config = null; - public static Config load() { + public static Config load() throws IOException { if (!configFilePath.toFile().exists()) { config = new Config(); save(); return config; } - try (var bf = new BufferedReader(new FileReader(configFilePath.toFile(), StandardCharsets.UTF_8))) { - config = gson.fromJson(bf, Config.class); - save(); - } catch (Exception e) { - RccServer.LOGGER.error("Error loading the RccServer config file.", e); - } + var bf = new BufferedReader(new FileReader(configFilePath.toFile(), StandardCharsets.UTF_8)); + config = gson.fromJson(bf, Config.class); + bf.close(); + save(); return config; }