diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt | 77 |
1 files changed, 22 insertions, 55 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt index 2741605ef..95f18c3c3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt @@ -34,17 +34,10 @@ object QuickModMenuSwitch { @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { val modsJar = event.getConstant<ModGuiSwitcherJson>("ModGuiSwitcher") - mods = buildList { - out@ for ((name, mod) in modsJar.mods) { - for (path in mod.guiPath) { - try { - Class.forName(path) - add(Mod(name, mod.description, mod.command, mod.guiPath)) - continue@out - } catch (_: Exception) { - } - } - } + mods = modsJar.mods.filter { mod -> + mod.value.guiPath.any { runCatching { Class.forName(it) }.isSuccess } + }.map { (name, mod) -> + Mod(name, mod.description, mod.command, mod.guiPath) } } @@ -108,11 +101,21 @@ object QuickModMenuSwitch { return config.javaClass.name } if (openGui == "cc.polyfrost.oneconfig.gui.OneConfigGui") { - /** TODO support different oneconfig mods: - * Partly Sane Skies - * Dankers SkyBlock Mod - * Dulkir - */ + val actualGui = Minecraft.getMinecraft().currentScreen + val currentPage = actualGui.javaClass.getDeclaredField("currentPage") + .makeAccessible() + .get(actualGui) + if (currentPage.javaClass.simpleName == "ModConfigPage") { + val optionPage = currentPage.javaClass.getDeclaredField("page") + .makeAccessible() + .get(currentPage) + val mod = optionPage.javaClass.getField("mod") + .makeAccessible() + .get(optionPage) + val modName = mod.javaClass.getField("name") + .get(mod) as String + return "cc.polyfrost.oneconfig.gui.OneConfigGui:$modName" + } } return openGui @@ -132,7 +135,7 @@ object QuickModMenuSwitch { Renderable.string(nameFormat + mod.name), bypassChecks = true, onClick = { open(mod) }, - condition = { System.currentTimeMillis() > lastGuiOpen + 250 } + condition = { System.currentTimeMillis() > lastGuiOpen + 250 }, ) add(listOf(renderable, nameSuffix)) } @@ -143,44 +146,8 @@ object QuickModMenuSwitch { currentlyOpeningMod = mod.name update() try { - when (mod.command) { - "patcher" -> { - val patcher = Class.forName("club.sk1er.patcher.Patcher") - val instance = patcher.getDeclaredField("instance").get(null) - val config = instance.javaClass.getDeclaredMethod("getPatcherConfig").invoke(instance) - val gui = Class.forName("gg.essential.vigilance.Vigilant").getDeclaredMethod("gui").invoke(config) - val guiUtils = Class.forName("gg.essential.api.utils.GuiUtil") - for (method in guiUtils.declaredMethods) { - try { - method.invoke(null, gui) - return - } catch (_: Exception) { - } - } - ErrorManager.skyHanniError("Error trying to open the gui for mod " + mod.name + "!") - } - - "hytil" -> { - val hytilsReborn = Class.forName("cc.woverflow.hytils.HytilsReborn") - val instance = hytilsReborn.getDeclaredField("INSTANCE").get(null) - val config = instance.javaClass.getDeclaredMethod("getConfig").invoke(instance) - val gui = Class.forName("gg.essential.vigilance.Vigilant").getDeclaredMethod("gui").invoke(config) - val guiUtils = Class.forName("gg.essential.api.utils.GuiUtil") - for (method in guiUtils.declaredMethods) { - try { - method.invoke(null, gui) - return - } catch (_: Exception) { - } - } - ChatUtils.chat("Error trying to open the gui for mod " + mod.name + "!") - } - - else -> { - val thePlayer = Minecraft.getMinecraft().thePlayer - ClientCommandHandler.instance.executeCommand(thePlayer, "/${mod.command}") - } - } + val thePlayer = Minecraft.getMinecraft().thePlayer + ClientCommandHandler.instance.executeCommand(thePlayer, "/" + mod.command) } catch (e: Exception) { ErrorManager.logErrorWithData(e, "Error trying to open the gui for mod " + mod.name) } |