aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-26 12:12:06 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-26 12:12:06 +0100
commitd0bef35f6d876d00673112d72415cbb0643d65ba (patch)
tree6466dfdac4b93d662e1ca73226bf3d016d0bcf82 /src/main
parenta7a952b657c3deacf55252d4adce39f4c05840ef (diff)
downloadskyhanni-d0bef35f6d876d00673112d72415cbb0643d65ba.tar.gz
skyhanni-d0bef35f6d876d00673112d72415cbb0643d65ba.tar.bz2
skyhanni-d0bef35f6d876d00673112d72415cbb0643d65ba.zip
Added MessageSendToServerEvent
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt22
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/MessageSendToServerEvent.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/SendCoordinatedCommand.kt27
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/ViewRecipeCommand.kt18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/WarpIsCommand.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/WikiManager.kt39
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/GetFromSacksTabComplete.kt26
7 files changed, 72 insertions, 76 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
index c7ddf1777..618636f63 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzActionBarEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.MessageSendToServerEvent
import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.features.chat.ChatFilterGui
import at.hannibal2.skyhanni.utils.IdentityCharacteristics
@@ -13,6 +14,7 @@ import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ChatLine
import net.minecraft.client.gui.GuiNewChat
import net.minecraft.event.HoverEvent
+import net.minecraft.network.play.client.C01PacketChatMessage
import net.minecraft.network.play.server.S02PacketChat
import net.minecraft.util.EnumChatFormatting
import net.minecraft.util.IChatComponent
@@ -64,13 +66,19 @@ object ChatManager {
@SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
fun onActionBarPacket(event: PacketEvent.ReceiveEvent) {
val packet = event.packet
- if (packet !is S02PacketChat) return
- val messageComponent = packet.chatComponent
+ if (packet is S02PacketChat) {
+ val messageComponent = packet.chatComponent
- val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText)
- if (packet.type.toInt() == 2) {
- val actionBarEvent = LorenzActionBarEvent(message)
- actionBarEvent.postAndCatch()
+ val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText)
+ if (packet.type.toInt() == 2) {
+ val actionBarEvent = LorenzActionBarEvent(message)
+ actionBarEvent.postAndCatch()
+ }
+ }
+
+ if (packet is C01PacketChatMessage) {
+ val message = packet.message
+ event.isCanceled = MessageSendToServerEvent(message).postAndCatch()
}
}
@@ -164,4 +172,4 @@ object ChatManager {
history.actionKind = ActionKind.RETRACTED
history.actionReason = reason.uppercase()
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/MessageSendToServerEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/MessageSendToServerEvent.kt
new file mode 100644
index 000000000..b6dff658e
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/MessageSendToServerEvent.kt
@@ -0,0 +1,6 @@
+package at.hannibal2.skyhanni.events
+
+import net.minecraftforge.fml.common.eventhandler.Cancelable
+
+@Cancelable
+class MessageSendToServerEvent(val message: String) : LorenzEvent()
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