From bf46a9ef4f8d0e792bb23a285ffd1a1ea5dda811 Mon Sep 17 00:00:00 2001 From: blackilykat Date: Mon, 4 Nov 2024 23:39:20 +0100 Subject: [PATCH] Move testbot auth location in config (doesnt break old configs) --- .../chipmunk/chipmunkmod/ChipmunkMod.java | 25 +++++++++++++++++-- .../chipmunk/chipmunkmod/Configuration.java | 2 +- .../chipmunkmod/mixin/ChatScreenMixin.java | 4 +-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java index d486642..2765b13 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java +++ b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java @@ -1,5 +1,7 @@ package land.chipmunk.chipmunkmod; +import com.google.gson.ExclusionStrategy; +import com.google.gson.FieldAttributes; import com.google.gson.GsonBuilder; import land.chipmunk.chipmunkmod.memory.ModuleMemory; import land.chipmunk.chipmunkmod.util.Keybinds; @@ -28,6 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gson.Gson; +// what the fuck is this indentation who is responsible for this nightmare public class ChipmunkMod implements ModInitializer { // This logger is used to write text to the console and the log file. // It is considered best practice to use your mod id as the logger's name. @@ -90,11 +93,29 @@ public class ChipmunkMod implements ModInitializer { InputStream is = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - return gson.fromJson(reader, Configuration.class); + Configuration configuration = gson.fromJson(reader, Configuration.class); + if(configuration.bots.testbot.webhookUrl == null && configuration.testbotWebhook != null) { + LOGGER.info("Updating testbot auth url location in config!"); + configuration.bots.testbot.webhookUrl = configuration.testbotWebhook; + configuration.testbotWebhook = null; + } + return configuration; } public static void saveConfig() throws IOException { - Gson otherGson = new GsonBuilder().serializeNulls().setLenient().setPrettyPrinting().create(); + // to migrate old configs and avoid confusion on which field to use. Exclusion strategy should be removed once no one has the old auth location + // in their configs anymore + Gson otherGson = new GsonBuilder().serializeNulls().setLenient().setPrettyPrinting().addSerializationExclusionStrategy(new ExclusionStrategy() { + @Override + public boolean shouldSkipField(FieldAttributes f) { + return f.getName().equals("testbotWebhook"); + } + + @Override + public boolean shouldSkipClass(Class clazz) { + return false; + } + }).create(); String defaultConfig = otherGson.toJson(CONFIG); BufferedWriter configWriter = new BufferedWriter(new FileWriter(CONFIG_FILE)); configWriter.write(defaultConfig); diff --git a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java index 125486e..4ad0554 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java +++ b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java @@ -11,8 +11,8 @@ public class Configuration { public Bots bots = new Bots(); public CustomChat customChat = new CustomChat(); public AntiSpam antiSpam = new AntiSpam(); - public boolean fullbright = true; // unused, but it is here for old configs public String autoSkinUsername = "off"; + // here so old configs can be migrated public String testbotWebhook = null; public String defaultUsername = null; public Memory memory = new Memory(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java index e43fa4d..292a627 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java @@ -65,10 +65,10 @@ public class ChatScreenMixin extends Screen { if (addToHistory) { client.inGameHud.getChatHud().addToMessageHistory(chatText); } - if(ChipmunkMod.CONFIG.testbotWebhook != null && chatText.startsWith("-")) { + if(ChipmunkMod.CONFIG.bots.testbot.webhookUrl != null && chatText.startsWith("-")) { Executor.service.submit(() -> { try { - Webhook.send(ChipmunkMod.CONFIG.testbotWebhook, ChipmunkMod.CONFIG.defaultUsername); + Webhook.send(ChipmunkMod.CONFIG.bots.testbot.webhookUrl, ChipmunkMod.CONFIG.defaultUsername); } catch (IOException e) { ChipmunkMod.LOGGER.error("fard webhook url !!!t"); e.printStackTrace();