From d0bef35f6d876d00673112d72415cbb0643d65ba Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 26 Nov 2023 12:12:06 +0100 Subject: Added MessageSendToServerEvent --- .../features/commands/SendCoordinatedCommand.kt | 27 ++++++--------- .../features/commands/ViewRecipeCommand.kt | 18 ++++------ .../skyhanni/features/commands/WarpIsCommand.kt | 10 +++--- .../skyhanni/features/commands/WikiManager.kt | 39 ++++++++++------------ .../tabcomplete/GetFromSacksTabComplete.kt | 26 +++++++-------- 5 files changed, 51 insertions(+), 69 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/SendCoordinatedCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/SendCoordinatedCommand.kt index 8cc303fcf..a41547c68 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/SendCoordinatedCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/SendCoordinatedCommand.kt @@ -1,26 +1,22 @@ package at.hannibal2.skyhanni.features.commands -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.MessageSendToServerEvent import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzUtils -import net.minecraft.network.play.client.C01PacketChatMessage import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class SendCoordinatedCommand { @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { - val packet = event.packet - if (packet is C01PacketChatMessage) { - val message = packet.message.lowercase() - if (message == "/sendcoords") { - event.isCanceled = true - LorenzUtils.sendMessageToServer(getCoordinates()) - } else if (message.startsWith("/sendcoords ")) { - event.isCanceled = true - val description = message.split(" ").drop(1).joinToString(" ") - LorenzUtils.sendMessageToServer("${getCoordinates()} $description") - } + fun onMessageSendToServer(event: MessageSendToServerEvent) { + val message = event.message + if (message == "/sendcoords") { + event.isCanceled = true + LorenzUtils.sendMessageToServer(getCoordinates()) + } else if (message.startsWith("/sendcoords ")) { + event.isCanceled = true + val description = message.split(" ").drop(1).joinToString(" ") + LorenzUtils.sendMessageToServer("${getCoordinates()} $description") } } @@ -32,5 +28,4 @@ class SendCoordinatedCommand { return "x: $x, y: $y, z: $z" } - -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/ViewRecipeCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/ViewRecipeCommand.kt index 4464959e2..147775fed 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/ViewRecipeCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/ViewRecipeCommand.kt @@ -1,26 +1,22 @@ package at.hannibal2.skyhanni.features.commands import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.MessageSendToServerEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems -import net.minecraft.network.play.client.C01PacketChatMessage import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object ViewRecipeCommand { private val config get() = SkyHanniMod.feature.commands @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { + fun onMessageSendToServer(event: MessageSendToServerEvent) { if (!config.viewRecipeLowerCase) return - val packet = event.packet - if (packet is C01PacketChatMessage) { - val message = packet.message - if (message == message.uppercase()) return - if (message.startsWith("/viewrecipe ", ignoreCase = true)) { - event.isCanceled = true - LorenzUtils.sendMessageToServer(message.uppercase()) - } + val message = event.message + if (message == message.uppercase()) return + if (message.startsWith("/viewrecipe ", ignoreCase = true)) { + event.isCanceled = true + LorenzUtils.sendMessageToServer(message.uppercase()) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/WarpIsCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/WarpIsCommand.kt index eb9ea503e..4cb06b568 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/WarpIsCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/WarpIsCommand.kt @@ -1,22 +1,20 @@ package at.hannibal2.skyhanni.features.commands import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.MessageSendToServerEvent import at.hannibal2.skyhanni.utils.LorenzUtils -import net.minecraft.network.play.client.C01PacketChatMessage import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class WarpIsCommand { @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { + fun onMessageSendToServer(event: MessageSendToServerEvent) { if (!LorenzUtils.inSkyBlock) return if (!SkyHanniMod.feature.commands.replaceWarpIs) return - val packet = event.packet - if (packet is C01PacketChatMessage && packet.message.lowercase() == "/warp is") { + if (event.message.lowercase() == "/warp is") { event.isCanceled = true LorenzUtils.sendMessageToServer("/is") } } -} \ 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 index de7cc4408..b3bdbe42c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt @@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.commands import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.MessageSendToServerEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment @@ -13,7 +13,6 @@ 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.minecraft.network.play.client.C01PacketChatMessage import net.minecraftforge.client.event.GuiScreenEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -32,29 +31,25 @@ class WikiManager { } @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { + fun onMessageSendToServer(event: MessageSendToServerEvent) { 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("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("Searching the Fandom Wiki for §a$search") - val wikiUrlCustom = "$urlSearchPrefix$search&scope=internal" - OSUtils.openBrowser(wikiUrlCustom.replace(' ', '+')) - } + 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(' ', '+')) } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/GetFromSacksTabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/GetFromSacksTabComplete.kt index b3770c6cc..f3738c6b4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/GetFromSacksTabComplete.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/GetFromSacksTabComplete.kt @@ -1,11 +1,10 @@ package at.hannibal2.skyhanni.features.commands.tabcomplete import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.data.jsonobjects.repo.SacksJson +import at.hannibal2.skyhanni.events.MessageSendToServerEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.data.jsonobjects.repo.SacksJson -import net.minecraft.network.play.client.C01PacketChatMessage import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object GetFromSacksTabComplete { @@ -26,19 +25,18 @@ object GetFromSacksTabComplete { } @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { + fun onMessageSendToServer(event: MessageSendToServerEvent) { if (!isEnabled()) return - val packet = event.packet as? C01PacketChatMessage ?: return - val message = packet.message - if (commands.any { message.startsWith("/$it ") }) { - val rawName = message.split(" ")[1] - val realName = rawName.replace("_", " ") - if (realName == rawName) return - if (realName !in sackList) return - event.isCanceled = true - LorenzUtils.sendMessageToServer(message.replace(rawName, realName)) - } + val message = event.message + if (!commands.any { message.startsWith("/$it ") }) return + + val rawName = message.split(" ")[1] + val realName = rawName.replace("_", " ") + if (realName == rawName) return + if (realName !in sackList) return + event.isCanceled = true + LorenzUtils.sendMessageToServer(message.replace(rawName, realName)) } fun isEnabled() = LorenzUtils.inSkyBlock && config.gfsSack -- cgit