add reload config
ig custom chat mabe mabe mabe
This commit is contained in:
parent
7437d0dd77
commit
cbfbe612bd
4 changed files with 45 additions and 1 deletions
|
@ -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()
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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\"]}";
|
||||
|
|
Loading…
Reference in a new issue