diff --git a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java index 211140b..ab8ee0e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java +++ b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java @@ -41,7 +41,7 @@ public class ChipmunkMod implements ModInitializer { LOGGER.info("Loaded ChipmunkMod (chayapak's fork)"); } - private static Configuration loadConfig () throws IOException { + public static Configuration loadConfig () throws IOException { CONFIG_DIR.mkdirs(); final Gson gson = new GsonBuilder() diff --git a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java index 7e3e847..d86dc22 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java +++ b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java @@ -39,6 +39,7 @@ public class CommandManager { SayCommand.register(this.dispatcher); SelfCareCommand.register(this.dispatcher); AutoSkinCommand.register(this.dispatcher); + ReloadConfigCommand.register(this.dispatcher); } public void executeCommand (String command) { diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java new file mode 100644 index 0000000..8af6f2a --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java @@ -0,0 +1,39 @@ +package land.chipmunk.chipmunkmod.commands; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import land.chipmunk.chipmunkmod.ChipmunkMod; +import land.chipmunk.chipmunkmod.modules.CustomChat; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.text.Text; + +import java.io.IOException; + +import static land.chipmunk.chipmunkmod.command.CommandManager.literal; + +public class ReloadConfigCommand { + public static void register (CommandDispatcher dispatcher) { + dispatcher.register( + literal("reloadconfig") + .executes(ReloadConfigCommand::reload) + ); + } + + public static int reload(CommandContext context) { + final FabricClientCommandSource source = context.getSource(); + + try { + ChipmunkMod.CONFIG = ChipmunkMod.loadConfig(); + + CustomChat.INSTANCE.reloadFormat(); + + source.sendFeedback(Text.literal("Successfully reloaded the config")); + } catch (IOException e) { + source.sendError(Text.literal("Could not load config, check the logs for stacktrace")); + e.printStackTrace(); + } + + return Command.SINGLE_SUCCESS; + } +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java index 0e8440e..298ab21 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java @@ -24,6 +24,10 @@ public class CustomChat { public CustomChat (MinecraftClient client) { this.client = client; + reloadFormat(); + } + + public void reloadFormat () { final JsonElement formatString = ChipmunkMod.CONFIG.customChat.format; if (formatString == null) format = "{\"translate\":\"chat.type.text\",\"with\":[\"USERNAME\",\"MESSAGE\"]}";