aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErymanthus[#5074] | (u/)RayDeeUx <51521765+RayDeeUx@users.noreply.github.com>2023-10-28 13:00:19 -0400
committerGitHub <noreply@github.com>2023-10-28 19:00:19 +0200
commit155af1305a5b65d0aac93e214ba6bead3a4d4e72 (patch)
tree4e295886ad2f3a2d34f8673482826d41a5b80d9a
parent82e39c24bb45c73bf9a258e63134acd4104efe53 (diff)
downloadskyhanni-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
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java29
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/WikiCommand.kt34
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt82
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/FandomWikiFromMenus.kt66
6 files changed, 179 insertions, 42 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index e98aea83f..7002ff0f5 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -71,7 +71,7 @@ import at.hannibal2.skyhanni.features.commands.PartyCommands
import at.hannibal2.skyhanni.features.commands.SendCoordinatedCommand
import at.hannibal2.skyhanni.features.commands.ViewRecipeCommand
import at.hannibal2.skyhanni.features.commands.WarpIsCommand
-import at.hannibal2.skyhanni.features.commands.WikiCommand
+import at.hannibal2.skyhanni.features.commands.WikiManager
import at.hannibal2.skyhanni.features.commands.tabcomplete.GetFromSacksTabComplete
import at.hannibal2.skyhanni.features.commands.tabcomplete.PlayerTabComplete
import at.hannibal2.skyhanni.features.commands.tabcomplete.WarpTabComplete
@@ -190,6 +190,7 @@ import at.hannibal2.skyhanni.features.misc.CollectionTracker
import at.hannibal2.skyhanni.features.misc.CurrentPetDisplay
import at.hannibal2.skyhanni.features.misc.CustomTextBox
import at.hannibal2.skyhanni.features.misc.ExpOrbsOnGroundHider
+import at.hannibal2.skyhanni.features.misc.FandomWikiFromMenus
import at.hannibal2.skyhanni.features.misc.FixNEUHeavyPearls
import at.hannibal2.skyhanni.features.misc.HideArmor
import at.hannibal2.skyhanni.features.misc.InGameDateDisplay
@@ -391,6 +392,7 @@ class SkyHanniMod {
loadModule(ItemDisplayOverlayFeatures())
loadModule(CurrentPetDisplay())
loadModule(ExpOrbsOnGroundHider())
+ loadModule(FandomWikiFromMenus())
loadModule(DamageIndicatorManager())
loadModule(ItemAbilityCooldown())
loadModule(DungeonHighlightClickedBlocks())
@@ -418,7 +420,7 @@ class SkyHanniMod {
loadModule(MinionFeatures())
loadModule(TimeFeatures())
loadModule(RngMeterInventory())
- loadModule(WikiCommand())
+ loadModule(WikiManager())
loadModule(SendCoordinatedCommand())
loadModule(WarpIsCommand())
loadModule(ViewRecipeCommand)
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
index abd448ccd..69a77d6df 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
@@ -9,7 +9,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {
val logger = LorenzLogger("ConfigMigration")
- val configVersion = 5
+ val configVersion = 6
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
@@ -94,4 +94,4 @@ object ConfigUpdaterMigrator {
logger.log("Final config: $it")
}
}
-} \ No newline at end of file
+}
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 12b7610ae..ed90268d5 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java
@@ -4,7 +4,9 @@ import at.hannibal2.skyhanni.config.FeatureToggle;
import com.google.gson.annotations.Expose;
import io.github.moulberry.moulconfig.annotations.Accordion;
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
+import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind;
import io.github.moulberry.moulconfig.annotations.ConfigOption;
+import org.lwjgl.input.Keyboard;
public class CommandsConfig {
@@ -68,11 +70,30 @@ public class CommandsConfig {
public boolean viewrecipeItems = true;
}
+ @ConfigOption(name = "Fandom Wiki for §e/wiki", desc = "")
+ @Accordion
@Expose
- @ConfigOption(name = "Fandom Wiki", desc = "Use Fandom wiki (§ehypixel-skyblock.fandom.com§7) instead of the Hypixel wiki (§ewiki.hypixel.net§7).")
- @ConfigEditorBoolean
- @FeatureToggle
- public boolean useFandomWiki = false;
+ public FandomWikiCommmandConfig fandomWiki = new FandomWikiCommmandConfig();
+
+ 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.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean useFandomWiki = 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
+ @ConfigOption(name = "Fandom Wiki Key", desc = "Search for an item on Fandom Wiki with this keybind.\n§4For optimal experiences, do §lNOT§r §4bind this to a mouse button.")
+ @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
+ public int fandomWikiKeybind = Keyboard.KEY_NONE;
+ }
@ConfigOption(name = "Party Commands", desc = "Shortens party commands and allows tab-completing for them. " +
"\n§eCommands: /pt /pp /pko /pk §7SkyBlock command §e/pt §7to check the play time still works.")
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
+}