summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
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
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')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt106
-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
3 files changed, 138 insertions, 108 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 b3bdbe42c..c1aab3a1c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt
@@ -9,21 +9,20 @@ 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.client.gui.inventory.GuiContainer
import net.minecraft.item.ItemStack
import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.net.URLEncoder
-class WikiManager {
+object WikiManager {
+ private const val OFFICIAL_URL_PREFIX = "https://wiki.hypixel.net/"
+ private const val OFFICIAL_SEARCH_PREFIX = "index.php?search="
+ private const val FANDOM_URL_PREFIX = "https://hypixel-skyblock.fandom.com/wiki/"
+ private const val FANDOM_SEARCH_PREFIX = "Special:Search?query="
- private val config get() = SkyHanniMod.feature.commands.fandomWiki
-
- companion object {
- private val urlPrefix = "https://hypixel-skyblock.fandom.com/wiki/"
- val urlSearchPrefix = "${urlPrefix}Special:Search?query="
- }
+ private val config get() = SkyHanniMod.feature.commands.betterWiki
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
@@ -34,23 +33,26 @@ class WikiManager {
fun onMessageSendToServer(event: MessageSendToServerEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!isEnabled()) return
-
val message = event.message.lowercase()
if (!(message.startsWith("/wiki"))) return
+
event.isCanceled = true
if (message == "/wiki") {
- LorenzUtils.chat("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 = event.message.split("/wiki ").last()
- LorenzUtils.chat("Searching the Fandom Wiki for §a$search")
- val wikiUrlCustom = "$urlSearchPrefix$search&scope=internal"
- OSUtils.openBrowser(wikiUrlCustom.replace(' ', '+'))
+ sendWikiMessage()
+ return
+ }
+ if (message.startsWith("/wiki ")) {
+ val search = event.message.drop("/wiki ".length)
+ sendWikiMessage(search)
+ return
+ }
+ if (message == ("/wikithis")) {
+ val itemInHand = InventoryUtils.getItemInHand() ?: run {
+ LorenzUtils.chat("§cYou must be holding an item to use this command!")
+ return
}
+ wikiTheItem(itemInHand, config.autoOpenWiki)
+ return
}
}
@@ -61,17 +63,65 @@ class WikiManager {
if (NEUItems.neuHasFocus()) return //because good heavens if this worked on neuitems...
val stack = gui.slotUnderMouse?.stack ?: return
- if (!config.fandomWikiKeybind.isKeyHeld()) return
- wikiTheItem(stack)
+ if (!config.wikiKeybind.isKeyHeld()) return
+ wikiTheItem(stack, config.menuOpenWiki)
}
- private fun wikiTheItem(item: ItemStack) {
- val itemDisplayName = (item.nameWithEnchantment ?: return).replace("§a✔ ", "").replace("§c✖ ", "")
+ private fun wikiTheItem(item: ItemStack, autoOpen: Boolean, useFandom: Boolean = config.useFandom) {
+ val itemDisplayName =
+ (item.nameWithEnchantment ?: return).replace("§a✔ ", "").replace("§c✖ ", "")
val internalName = item.getInternalName().asString()
- LorenzUtils.chat("Searching the Fandom Wiki for §a$itemDisplayName")
- val wikiUrlSearch = if (internalName != "NONE") "$urlSearchPrefix$internalName&scope=internal"
- else "$urlSearchPrefix${itemDisplayName.removeColor()}&scope=internal"
- OSUtils.openBrowser(wikiUrlSearch.replace(' ', '+'))
+ val wikiUrlSearch = if (internalName != "NONE") internalName else itemDisplayName.removeColor()
+
+ sendWikiMessage(wikiUrlSearch, itemDisplayName.removeColor(), autoOpen, useFandom)
+ }
+
+ fun otherWikiCommands(args: Array<String>, useFandom: Boolean, wikithis: Boolean = false) {
+ if (wikithis && !LorenzUtils.inSkyBlock) {
+ LorenzUtils.chat("§cYou must be in SkyBlock to do this!")
+ return
+ }
+
+ var search = ""
+ for (arg in args) search = "$search${arg}"
+
+ if (wikithis) {
+ val itemInHand = InventoryUtils.getItemInHand() ?: run {
+ LorenzUtils.chat("§cYou must be holding an item to use this command!")
+ return
+ }
+ wikiTheItem(itemInHand, false, useFandom = useFandom)
+ return
+ }
+ if (search == "") {
+ sendWikiMessage(useFandom = useFandom)
+ return
+ }
+ sendWikiMessage(search, useFandom = useFandom)
+ }
+
+ fun sendWikiMessage(
+ search: String = "", displaySearch: String = search,
+ autoOpen: Boolean = config.autoOpenWiki, useFandom: Boolean = config.useFandom
+ ) {
+ val wiki = if (useFandom) "SkyBlock Fandom Wiki" else "Official SkyBlock Wiki"
+ val urlPrefix = if (useFandom) FANDOM_URL_PREFIX else OFFICIAL_URL_PREFIX
+ if (search == "") {
+ LorenzUtils.clickableLinkChat(
+ "§7Click §e§lHERE §7to visit the §6$wiki§7!", urlPrefix, "§7The $wiki!"
+ )
+ return
+ }
+
+ val urlSearchPrefix = if (useFandom) "$urlPrefix$FANDOM_SEARCH_PREFIX" else "$urlPrefix$OFFICIAL_SEARCH_PREFIX"
+ val searchUrl = "$urlSearchPrefix${URLEncoder.encode(search, "UTF-8")}&scope=internal"
+
+ LorenzUtils.clickableLinkChat(
+ "§7Click §e§lHERE §7to find §a$displaySearch §7on the §6$wiki§7!",
+ searchUrl,
+ "§7View §a$displaySearch §7on the §6$wiki§7!",
+ autoOpen
+ )
}
private fun isEnabled() = config.enabled
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
-}