Bugfix /rcc reload
not reporting config error.
This commit is contained in:
parent
0110a4ceaf
commit
20bcb2f081
3 changed files with 21 additions and 12 deletions
|
@ -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<MessageType> 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));
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue