add reload config

ig custom chat mabe mabe mabe
This commit is contained in:
Chayapak 2023-05-13 12:11:52 +07:00
parent 7437d0dd77
commit cbfbe612bd
4 changed files with 45 additions and 1 deletions

View file

@ -41,7 +41,7 @@ public class ChipmunkMod implements ModInitializer {
LOGGER.info("Loaded ChipmunkMod (chayapak's fork)"); LOGGER.info("Loaded ChipmunkMod (chayapak's fork)");
} }
private static Configuration loadConfig () throws IOException { public static Configuration loadConfig () throws IOException {
CONFIG_DIR.mkdirs(); CONFIG_DIR.mkdirs();
final Gson gson = new GsonBuilder() final Gson gson = new GsonBuilder()

View file

@ -39,6 +39,7 @@ public class CommandManager {
SayCommand.register(this.dispatcher); SayCommand.register(this.dispatcher);
SelfCareCommand.register(this.dispatcher); SelfCareCommand.register(this.dispatcher);
AutoSkinCommand.register(this.dispatcher); AutoSkinCommand.register(this.dispatcher);
ReloadConfigCommand.register(this.dispatcher);
} }
public void executeCommand (String command) { public void executeCommand (String command) {

View file

@ -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<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("reloadconfig")
.executes(ReloadConfigCommand::reload)
);
}
public static int reload(CommandContext<FabricClientCommandSource> 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;
}
}

View file

@ -24,6 +24,10 @@ public class CustomChat {
public CustomChat (MinecraftClient client) { public CustomChat (MinecraftClient client) {
this.client = client; this.client = client;
reloadFormat();
}
public void reloadFormat () {
final JsonElement formatString = ChipmunkMod.CONFIG.customChat.format; final JsonElement formatString = ChipmunkMod.CONFIG.customChat.format;
if (formatString == null) format = "{\"translate\":\"chat.type.text\",\"with\":[\"USERNAME\",\"MESSAGE\"]}"; if (formatString == null) format = "{\"translate\":\"chat.type.text\",\"with\":[\"USERNAME\",\"MESSAGE\"]}";