diff options
author | Erymanthus[#5074] | (u/)RayDeeUx <51521765+RayDeeUx@users.noreply.github.com> | 2023-10-28 13:00:19 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-28 19:00:19 +0200 |
commit | 155af1305a5b65d0aac93e214ba6bead3a4d4e72 (patch) | |
tree | 4e295886ad2f3a2d34f8673482826d41a5b80d9a /src/main/java/at/hannibal2/skyhanni/features | |
parent | 82e39c24bb45c73bf9a258e63134acd4104efe53 (diff) | |
download | skyhanni-155af1305a5b65d0aac93e214ba6bead3a4d4e72.tar.gz skyhanni-155af1305a5b65d0aac93e214ba6bead3a4d4e72.tar.bz2 skyhanni-155af1305a5b65d0aac93e214ba6bead3a4d4e72.zip |
Change: switch to internal fandom wiki search engine, increase scope of skyhanni's /wiki command to include any item whose item lore includes wiki. (#494)
Added option to change hypixel wiki to fandom wiki in more areas than just the /wiki command. #494
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
3 files changed, 148 insertions, 34 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/WikiCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/WikiCommand.kt deleted file mode 100644 index 4976c4d9f..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/WikiCommand.kt +++ /dev/null @@ -1,34 +0,0 @@ -package at.hannibal2.skyhanni.features.commands - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.PacketEvent -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.OSUtils -import net.minecraft.network.play.client.C01PacketChatMessage -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class WikiCommand { - - @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { - val packet = event.packet - - if (!SkyHanniMod.feature.commands.useFandomWiki) return - - if (packet is C01PacketChatMessage) { - val message = packet.message.lowercase() - if (message == "/wiki") { - event.isCanceled = true - OSUtils.openBrowser("https://hypixel-skyblock.fandom.com/wiki/Hypixel_SkyBlock_Wiki") - LorenzUtils.chat("§e[SkyHanni] Opening the Fandom Wiki..") - } else if (message.startsWith("/wiki ")) { - event.isCanceled = true - val search = packet.message.substring(6) - LorenzUtils.chat("§e[SkyHanni] Searching the Fandom Wiki for §c$search") - - val url = "https://www.google.com/search?q=inurl%3Ahypixel-skyblock.fandom.com $search&hl=en" - OSUtils.openBrowser(url.replace(' ', '+')) - } - } - } -}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt new file mode 100644 index 000000000..119e01d66 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt @@ -0,0 +1,82 @@ +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.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.item.ItemStack +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=" + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(6, "commands.useFandomWiki", "commands.fandomWiki.useFandomWiki") + } + + @SubscribeEvent + fun onSendPacket(event: PacketEvent.SendEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!isEnabled()) return + + val packet = event.packet + + if (packet is C01PacketChatMessage) { + val message = packet.message.lowercase() + if (!(message.startsWith("/wiki"))) return + event.isCanceled = true + if (message == "/wiki") { + LorenzUtils.chat("§e[SkyHanni] Opening the Fandom 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 + wikiTheItem(itemInHand) + } else { + val search = packet.message.split("/wiki ").last() + LorenzUtils.chat("§e[SkyHanni] Searching the Fandom Wiki for §a$search") + val wikiUrlCustom = "$urlSearchPrefix$search&scope=internal" + OSUtils.openBrowser(wikiUrlCustom.replace(' ', '+')) + } + } + } + } + + @SubscribeEvent + fun onKeyClickWithTooltipActive(event: LorenzToolTipEvent) { + if (!LorenzUtils.inSkyBlock) return + if (Minecraft.getMinecraft().currentScreen == null) return + if (NEUItems.neuHasFocus()) return //because good heavens if this worked on neuitems... + + if (Keyboard.isKeyDown(config.fandomWikiKeybind)) { + val itemUnderCursor = event.itemStack ?: return + wikiTheItem(itemUnderCursor) + } + } + + private fun wikiTheItem(item: ItemStack) { + var wikiUrlSearch = "" + val itemDisplayName = (item.nameWithEnchantment ?: return).replace("§a✔ ", "").replace("§c✖ ", "") + val internalName = item.getInternalName().asString() ?: return + 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" + OSUtils.openBrowser(wikiUrlSearch.replace(' ', '+')) + } + + private fun isEnabled() = config.useFandomWiki +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/FandomWikiFromMenus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/FandomWikiFromMenus.kt new file mode 100644 index 000000000..d2c1ab4f3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/FandomWikiFromMenus.kt @@ -0,0 +1,66 @@ +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.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.anyContains +import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import io.github.moulberry.notenoughupdates.events.SlotClickEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +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) { + event.move(6, "fandomWiki", "commands.fandomWiki") + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onSlotClick(event: SlotClickEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!isEnabled()) return + val chestName = InventoryUtils.openInventoryName() + + if (chestName.isEmpty()) return + + val itemClickedStack = event.slot.stack + val itemClickedName = itemClickedStack.displayName + val itemInHand = InventoryUtils.getItemInHand() ?: return + val itemInHandName = itemInHand.nameWithEnchantment ?: return + val internalName = itemInHand.getInternalName().asString() ?: return + + var wikiDisplayName = "" + var wikiInternalName = "" + + if ((itemInHandName == "") || (event.slotId == 11 && itemClickedName.contains("Wiki Command") && chestName.contains("Wiki"))) { + 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")) { + wikiDisplayName = itemInHandName + 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 + if (!config.skipWikiChat) { + 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" + OSUtils.openBrowser(wikiUrlCustom.replace(' ', '+')) + } + event.isCanceled = true + } + private fun isEnabled() = config.useFandomWiki +} |