summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/commands
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-10-28 19:01:55 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-10-28 19:01:55 +0200
commit9990094370612b8523c8f2622399d01c5697c0a7 (patch)
treec922d678b0f3a489fb113be6435b8c35b0092666 /src/main/java/at/hannibal2/skyhanni/features/commands
parent155af1305a5b65d0aac93e214ba6bead3a4d4e72 (diff)
downloadskyhanni-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
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/commands')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt39
1 files changed, 20 insertions, 19 deletions
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
}