From 83951beb85032ca11eede16a11adb27ccc6042a4 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:26:11 +0100 Subject: Added debug command /shconfigmanagerreset --- .../hannibal2/skyhanni/config/ConfigGuiManager.kt | 11 ++++-- .../at/hannibal2/skyhanni/config/ConfigManager.kt | 9 ++++- .../hannibal2/skyhanni/config/commands/Commands.kt | 4 +++ .../hannibal2/skyhanni/config/features/About.java | 2 +- .../skyhanni/test/SkyHanniDebugsAndTests.kt | 39 +++++++++++++++++++++- 5 files changed, 59 insertions(+), 6 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigGuiManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigGuiManager.kt index 37c2920a5..9708c513b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigGuiManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigGuiManager.kt @@ -5,14 +5,19 @@ import io.github.moulberry.moulconfig.gui.GuiScreenElementWrapper import io.github.moulberry.moulconfig.gui.MoulConfigEditor object ConfigGuiManager { - val editor by lazy { MoulConfigEditor(SkyHanniMod.configManager.processor) } + + var editor: MoulConfigEditor? = null fun openConfigGui(search: String? = null) { + if (editor == null) { + editor = MoulConfigEditor(SkyHanniMod.configManager.processor) + } + val editor = editor ?: return + if (search != null) { editor.search(search) } SkyHanniMod.screenToOpen = GuiScreenElementWrapper(editor) } - -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index a05d2de5d..bfbeb08df 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -109,6 +109,7 @@ class ConfigManager { private var configFile: File? = null private var sackFile: File? = null lateinit var processor: MoulConfigProcessor + private var disableSaving = false fun firstLoad() { if (::features.isInitialized) { @@ -217,6 +218,7 @@ class ConfigManager { } fun saveConfig(reason: String) { + if (disableSaving) return logger.log("saveConfig: $reason") val file = configFile ?: throw Error("Can not save config, configFile is null!") try { @@ -242,6 +244,7 @@ class ConfigManager { } fun saveSackData(reason: String) { + if (disableSaving) return logger.log("saveSackData: $reason") val file = sackFile ?: throw Error("Can not save sacks, sackFile is null!") try { @@ -256,4 +259,8 @@ class ConfigManager { e.printStackTrace() } } -} \ No newline at end of file + + fun disableSaving() { + disableSaving = true + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 3fdc56073..ea77de371 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -284,6 +284,10 @@ object Commands { "shplaysound", "Play the specified sound effect at the given pitch and volume." ) { SoundUtils.command(it) } + registerCommand( + "shconfigmanagerreset", + "Reloads the config manager and rendering processors of MoulConfig. This §cWILL RESET §7your config, but also updating the java config files (names, description, orderings and stuff)." + ) { SkyHanniDebugsAndTests.configManagerResetCommand(it) } } private fun internalCommands() { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/About.java b/src/main/java/at/hannibal2/skyhanni/config/features/About.java index 349cb7466..258ba6985 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/About.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/About.java @@ -81,4 +81,4 @@ public class About { @ConfigEditorButton(buttonText = "GitHub") public Runnable discordRPC = () -> OSUtils.openBrowser("https://github.com/jagrosh/DiscordIPC"); } -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt index 745cbcb97..d58c12a14 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt @@ -1,6 +1,8 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigGuiManager +import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.SlayerAPI @@ -20,6 +22,7 @@ import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzDebug import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull @@ -98,6 +101,40 @@ class SkyHanniDebugsAndTests { // } } + fun configManagerResetCommand(args: Array) { + if (args.size == 1 && args[0] == "confirm") { + configManagerReset() + return + } + + LorenzUtils.clickableChat( + "§cTHIS WILL RESET YOUR SkyHanni CONFIG! Click here to procceed.", + "shconfigmanagerreset confirm" + ) + } + + private fun configManagerReset() { + // TODO make it so that it does not reset the config + + // saving old config state + SkyHanniMod.configManager.saveConfig("reload config manager") + SkyHanniMod.configManager.saveSackData("reload config manager") + Thread { + Thread.sleep(500) + SkyHanniMod.configManager.disableSaving() + + // inizialising a new config manager, calling firstLoad, and setting it as the config manager in use. + val configManager = ConfigManager() + configManager.firstLoad() + SkyHanniMod.Companion::class.java.enclosingClass.getDeclaredField("configManager").makeAccessible() + .set(SkyHanniMod, configManager) + + // resetting the MoulConfigProcessor in use + ConfigGuiManager.editor = null + LorenzUtils.chat("§e[SkyHanni] Reseted the config manager!") + }.start() + } + fun testGardenVisitors() { if (displayList.isNotEmpty()) { displayList = mutableListOf() @@ -574,4 +611,4 @@ class SkyHanniDebugsAndTests { event.move(3, "dev.showNpcPrice", "dev.debug.showNpcPrice") } -} \ No newline at end of file +} -- cgit