diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-10-28 19:01:55 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-10-28 19:01:55 +0200 |
commit | 9990094370612b8523c8f2622399d01c5697c0a7 (patch) | |
tree | c922d678b0f3a489fb113be6435b8c35b0092666 | |
parent | 155af1305a5b65d0aac93e214ba6bead3a4d4e72 (diff) | |
download | skyhanni-9990094370612b8523c8f2622399d01c5697c0a7.tar.gz skyhanni-9990094370612b8523c8f2622399d01c5697c0a7.tar.bz2 skyhanni-9990094370612b8523c8f2622399d01c5697c0a7.zip |
changed config toggle to enabled, changed hotkey logic to only trigger once, reformat code and code cleanup
3 files changed, 53 insertions, 38 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java index ed90268d5..cb127dc11 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java @@ -78,15 +78,14 @@ public class CommandsConfig { public static class FandomWikiCommmandConfig { @Expose - @ConfigOption(name = "Replace Chat", desc = "Use Fandom Wiki (§ehypixel-skyblock.fandom.com§7) instead of the Hypixel wiki (§ewiki.hypixel.net§7) in most wiki-related chat messages.") + @ConfigOption(name = "Enabled", desc = "Use Fandom Wiki (§ehypixel-skyblock.fandom.com§7) instead of the Hypixel wiki (§ewiki.hypixel.net§7) in most wiki-related chat messages.") @ConfigEditorBoolean @FeatureToggle - public boolean useFandomWiki = false; + public boolean enabled = false; @Expose @ConfigOption(name = "Skip Chat", desc = "Directly opens the Fandom Wiki instead of sending the §e\"Click to search for this thing on the Fandom Wiki\"§7 message beforehand.") @ConfigEditorBoolean - @FeatureToggle public boolean skipWikiChat = false; @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt index 119e01d66..c515cb7f0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt @@ -2,30 +2,33 @@ package at.hannibal2.skyhanni.features.commands import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraft.network.play.client.C01PacketChatMessage -import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.item.ItemStack +import net.minecraft.network.play.client.C01PacketChatMessage +import net.minecraftforge.client.event.GuiScreenEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.lwjgl.input.Keyboard class WikiManager { private val config get() = SkyHanniMod.feature.commands.fandomWiki - private val urlPrefix = "https://hypixel-skyblock.fandom.com/wiki/" - private val urlSearchPrefix = "${urlPrefix}Special:Search?query=" + + companion object { + private val urlPrefix = "https://hypixel-skyblock.fandom.com/wiki/" + val urlSearchPrefix = "${urlPrefix}Special:Search?query=" + } @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(6, "commands.useFandomWiki", "commands.fandomWiki.useFandomWiki") + event.move(6, "commands.useFandomWiki", "commands.fandomWiki.enabled") } @SubscribeEvent @@ -41,7 +44,7 @@ class WikiManager { event.isCanceled = true if (message == "/wiki") { LorenzUtils.chat("§e[SkyHanni] Opening the Fandom Wiki..") - OSUtils.openBrowser("${urlPrefix}/Hypixel_SkyBlock_Wiki") + OSUtils.openBrowser("${urlPrefix}Hypixel_SkyBlock_Wiki") } else if (message.startsWith("/wiki ") || message == ("/wikithis")) { //conditional to see if we need Special:Search page if (message == ("/wikithis")) { val itemInHand = InventoryUtils.getItemInHand() ?: return @@ -57,26 +60,24 @@ class WikiManager { } @SubscribeEvent - fun onKeyClickWithTooltipActive(event: LorenzToolTipEvent) { + fun onKeybind(event: GuiScreenEvent.KeyboardInputEvent.Post) { if (!LorenzUtils.inSkyBlock) return - if (Minecraft.getMinecraft().currentScreen == null) return + val gui = event.gui as? GuiContainer ?: return if (NEUItems.neuHasFocus()) return //because good heavens if this worked on neuitems... + val stack = gui.slotUnderMouse?.stack ?: return - if (Keyboard.isKeyDown(config.fandomWikiKeybind)) { - val itemUnderCursor = event.itemStack ?: return - wikiTheItem(itemUnderCursor) - } + if (!config.fandomWikiKeybind.isKeyHeld()) return + wikiTheItem(stack) } private fun wikiTheItem(item: ItemStack) { - var wikiUrlSearch = "" val itemDisplayName = (item.nameWithEnchantment ?: return).replace("§a✔ ", "").replace("§c✖ ", "") - val internalName = item.getInternalName().asString() ?: return + val internalName = item.getInternalName().asString() LorenzUtils.chat("§e[SkyHanni] Searching the Fandom Wiki for §a$itemDisplayName") - if (internalName != "NONE") wikiUrlSearch = "$urlSearchPrefix$internalName&scope=internal" - else wikiUrlSearch = "$urlSearchPrefix${itemDisplayName.removeColor()}&scope=internal" + val wikiUrlSearch = if (internalName != "NONE") "$urlSearchPrefix$internalName&scope=internal" + else "$urlSearchPrefix${itemDisplayName.removeColor()}&scope=internal" OSUtils.openBrowser(wikiUrlSearch.replace(' ', '+')) } - private fun isEnabled() = config.useFandomWiki + private fun isEnabled() = config.enabled } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/FandomWikiFromMenus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/FandomWikiFromMenus.kt index d2c1ab4f3..44d4b94ed 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/FandomWikiFromMenus.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/FandomWikiFromMenus.kt @@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.events.* +import at.hannibal2.skyhanni.features.commands.WikiManager import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore @@ -18,8 +18,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class FandomWikiFromMenus { private val config get() = SkyHanniMod.feature.commands.fandomWiki - private val urlPrefix = "https://hypixel-skyblock.fandom.com/wiki/" - private val urlSearchPrefix = "${urlPrefix}Special:Search?query=" @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { @@ -34,33 +32,50 @@ class FandomWikiFromMenus { if (chestName.isEmpty()) return - val itemClickedStack = event.slot.stack + val itemClickedStack = event.slot.stack ?: return val itemClickedName = itemClickedStack.displayName val itemInHand = InventoryUtils.getItemInHand() ?: return val itemInHandName = itemInHand.nameWithEnchantment ?: return - val internalName = itemInHand.getInternalName().asString() ?: return - var wikiDisplayName = "" - var wikiInternalName = "" + val wikiDisplayName: String + val wikiInternalName: String - if ((itemInHandName == "") || (event.slotId == 11 && itemClickedName.contains("Wiki Command") && chestName.contains("Wiki"))) { + val inWikiInventory = // TODO better name for this inventory + event.slotId == 11 && itemClickedName.contains("Wiki Command") && chestName.contains("Wiki") + if ((itemInHandName == "") || inWikiInventory) { LorenzUtils.clickableChat("§e[SkyHanni] Click here to visit the Hypixel Skyblock Fandom Wiki!", "wiki") return - } else if (event.slotId == 15 && itemClickedName.contains("Wikithis Command") && chestName.contains("Wiki")) { + } + + val inOtherWikiInventory = // TODO better name for this inventory + event.slotId == 15 && itemClickedName.contains("Wikithis Command") && chestName.contains("Wiki") + if (inOtherWikiInventory) { wikiDisplayName = itemInHandName + val internalName = itemInHand.getInternalName().asString() wikiInternalName = internalName - } else if ((itemClickedStack.getLore().anyContains("Wiki") || itemClickedStack.getLore().anyContains("wiki")) && !(itemClickedStack.getLore().anyContains("wikipedia"))) { //.lowercase() to match "Wiki!" and ".*wiki.*" lore lines in one fell swoop - wikiDisplayName = itemClickedName.removeColor().replace("✔ ", "").replace("✖ ", "") - wikiInternalName = itemClickedName.removeColor().replace("✔ ", "").replace("✖ ", "") - } else return + } else { + //.lowercase() to match "Wiki!" and ".*wiki.*" lore lines in one fell swoop + val inThirdWikiInventory = // TODO better name for this inventory + (itemClickedStack.getLore().anyContains("Wiki") || itemClickedStack.getLore().anyContains("wiki")) + && !itemClickedStack.getLore().anyContains("wikipedia") + if (inThirdWikiInventory) { + wikiDisplayName = itemClickedName.removeColor().replace("✔ ", "").replace("✖ ", "") + wikiInternalName = wikiDisplayName + } else return + } + if (!config.skipWikiChat) { - LorenzUtils.clickableChat("§e[SkyHanni] Click here to search for $wikiDisplayName §eon the Hypixel Skyblock Fandom Wiki!", "wiki $wikiInternalName") + LorenzUtils.clickableChat( + "§e[SkyHanni] Click here to search for $wikiDisplayName §eon the Hypixel Skyblock Fandom Wiki!", + "wiki $wikiInternalName" + ) } else { LorenzUtils.chat("§e[SkyHanni] Searching the Fandom Wiki for §a$wikiDisplayName") - val wikiUrlCustom = "$urlSearchPrefix$wikiInternalName&scope=internal" + val wikiUrlCustom = "${WikiManager.urlSearchPrefix}$wikiInternalName&scope=internal" OSUtils.openBrowser(wikiUrlCustom.replace(' ', '+')) } event.isCanceled = true } - private fun isEnabled() = config.useFandomWiki + + private fun isEnabled() = config.enabled } |