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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ public class RccServer implements ModInitializer {
|
||||||
public static final String MOD_ID = "rcc-server";
|
public static final String MOD_ID = "rcc-server";
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
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();
|
public static final StateManager state = new StateManager();
|
||||||
|
|
||||||
|
@ -62,10 +63,6 @@ public class RccServer implements ModInitializer {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RccServer() {
|
|
||||||
INSTANCE = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LuckPerms luckPerms;
|
private LuckPerms luckPerms;
|
||||||
|
|
||||||
public 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"));
|
public static final RegistryKey<MessageType> CHAT_TYPE = RegistryKey.of(RegistryKeys.MESSAGE_TYPE, new Identifier(MOD_ID, "chat"));
|
||||||
private static boolean warnedAboutUnsignedMessages = false;
|
private static boolean warnedAboutUnsignedMessages = false;
|
||||||
|
|
||||||
|
public RccServer() {
|
||||||
|
INSTANCE = this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
LOGGER.info("Starting rcc-server");
|
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 -> {
|
ServerLifecycleEvents.SERVER_STARTING.register(server -> {
|
||||||
RccServer.server = server;
|
RccServer.server = server;
|
||||||
state.register(server.getSavePath(WorldSavePath.ROOT).resolve("data").resolve(RccServer.MOD_ID));
|
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.server.command.ServerCommandSource;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
|
||||||
public class RccCommand {
|
public class RccCommand {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import net.fabricmc.loader.api.FabricLoader;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Path;
|
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 final Path configFilePath = FabricLoader.getInstance().getConfigDir().resolve(RccServer.MOD_ID + ".json");
|
||||||
private static Config config = null;
|
private static Config config = null;
|
||||||
|
|
||||||
public static Config load() {
|
public static Config load() throws IOException {
|
||||||
if (!configFilePath.toFile().exists()) {
|
if (!configFilePath.toFile().exists()) {
|
||||||
config = new Config();
|
config = new Config();
|
||||||
save();
|
save();
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
try (var bf = new BufferedReader(new FileReader(configFilePath.toFile(), StandardCharsets.UTF_8))) {
|
var bf = new BufferedReader(new FileReader(configFilePath.toFile(), StandardCharsets.UTF_8));
|
||||||
config = gson.fromJson(bf, Config.class);
|
config = gson.fromJson(bf, Config.class);
|
||||||
save();
|
bf.close();
|
||||||
} catch (Exception e) {
|
save();
|
||||||
RccServer.LOGGER.error("Error loading the RccServer config file.", e);
|
|
||||||
}
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue