summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/misc
diff options
context:
space:
mode:
authorObsidian <108832807+Obsidianninja11@users.noreply.github.com>2024-02-09 13:40:02 -0900
committerGitHub <noreply@github.com>2024-02-09 23:40:02 +0100
commit9cfdf252304e3fe270bd84ddcae292273a9927aa (patch)
treede3c91cc8b155ec15c21cb8646a322cbe44e478d /src/main/java/at/hannibal2/skyhanni/features/misc
parentd134fece41b7cfe4d8ff1c9176ff0e7f8a05420f (diff)
downloadskyhanni-9cfdf252304e3fe270bd84ddcae292273a9927aa.tar.gz
skyhanni-9cfdf252304e3fe270bd84ddcae292273a9927aa.tar.bz2
skyhanni-9cfdf252304e3fe270bd84ddcae292273a9927aa.zip
SkyHanni's own /wiki command logic now works better in SkyBlock Level guide and allows to change weather to use official Hypixel Wiki or the older Fandom Wiki. #831
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/BetterWikiFromMenus.kt60
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/FandomWikiFromMenus.kt80
2 files changed, 60 insertions, 80 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/BetterWikiFromMenus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/BetterWikiFromMenus.kt
new file mode 100644
index 000000000..a0ead6b7c
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/BetterWikiFromMenus.kt
@@ -0,0 +1,60 @@
+package at.hannibal2.skyhanni.features.misc
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
+import at.hannibal2.skyhanni.features.commands.WikiManager
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.LorenzUtils
+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 BetterWikiFromMenus {
+
+ private val config get() = SkyHanniMod.feature.commands.betterWiki
+
+ @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 ?: return
+ val itemClickedName = itemClickedStack.displayName
+
+ val isWiki = event.slotId == 11 && itemClickedName.contains("Wiki Command")
+ val isWikithis = event.slotId == 15 && itemClickedName.contains("Wikithis Command")
+ val inBiblioInventory = chestName == "SkyBlock Wiki" && (isWiki || isWikithis)
+ val inSBGuideInventory = (itemClickedStack.getLore().let { it.any { line -> line == "§7§eClick to view on the SkyBlock Wiki!" } })
+
+ if (inBiblioInventory) {
+ if (isWiki) {
+ WikiManager.sendWikiMessage(useFandom = true)
+ return
+ }
+
+ if (isWikithis) {
+ WikiManager.otherWikiCommands(arrayOf(""), true, true)
+ return
+ }
+ }
+
+ if (inSBGuideInventory && config.sbGuide) {
+ val wikiSearch = itemClickedName.removeColor().replace("✔ ", "").replace("✖ ", "")
+ WikiManager.sendWikiMessage(wikiSearch, autoOpen = config.menuOpenWiki)
+ event.isCanceled = true
+ }
+ }
+
+ 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
deleted file mode 100644
index dbc3725bf..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/FandomWikiFromMenus.kt
+++ /dev/null
@@ -1,80 +0,0 @@
-package at.hannibal2.skyhanni.features.misc
-
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
-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
-import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment
-import at.hannibal2.skyhanni.utils.LorenzUtils
-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
-
- @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 ?: return
- val itemClickedName = itemClickedStack.displayName
- val itemInHand = InventoryUtils.getItemInHand() ?: return
- val itemInHandName = itemInHand.nameWithEnchantment ?: return
-
- val wikiDisplayName: String
- val wikiInternalName: String
-
- val inWikiInventory = // TODO better name for this inventory
- event.slotId == 11 && itemClickedName.contains("Wiki Command") && chestName.contains("Wiki")
- if ((itemInHandName == "") || inWikiInventory) {
- LorenzUtils.clickableChat("Click here to visit the Hypixel Skyblock Fandom Wiki!", "wiki")
- return
- }
-
- 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 {
- //.lowercase() to match "Wiki!" and ".*wiki.*" lore lines in one fell swoop
- val inThirdWikiInventory = // TODO better name for this inventory
- (itemClickedStack.getLore()
- .let { it.any { line -> line == "§7§eClick to view on the SkyBlock" } && it.last() == "§eWiki!" })
- if (inThirdWikiInventory) {
- wikiDisplayName = itemClickedName.removeColor().replace("✔ ", "").replace("✖ ", "")
- wikiInternalName = wikiDisplayName
- } else return
- }
-
- if (!config.skipWikiChat) {
- LorenzUtils.clickableChat(
- "Click here to search for $wikiDisplayName §eon the Hypixel Skyblock Fandom Wiki!",
- "wiki $wikiInternalName"
- )
- } else {
- LorenzUtils.chat("Searching the Fandom Wiki for §a$wikiDisplayName")
- val wikiUrlCustom = "${WikiManager.urlSearchPrefix}$wikiInternalName&scope=internal"
- OSUtils.openBrowser(wikiUrlCustom.replace(' ', '+'))
- }
- event.isCanceled = true
- }
-
- private fun isEnabled() = config.enabled
-}