diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/chat/ChatManager.kt) | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt index f222705cb..38a50da6e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.features.chat +package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.events.LorenzActionBarEvent import at.hannibal2.skyhanni.events.LorenzChatEvent @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.network.play.server.S02PacketChat +import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -17,7 +18,7 @@ class ChatManager { private val loggerFilteredTypes = mutableMapOf<String, LorenzLogger>() @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onChatPacket(event: PacketEvent.ReceiveEvent) { + fun onActionBarPacket(event: PacketEvent.ReceiveEvent) { val packet = event.packet if (packet !is S02PacketChat) return val messageComponent = packet.chatComponent @@ -26,26 +27,30 @@ class ChatManager { if (packet.type.toInt() == 2) { val actionBarEvent = LorenzActionBarEvent(message) actionBarEvent.postAndCatch() - } else { - - val chatEvent = LorenzChatEvent(message, messageComponent) - chatEvent.postAndCatch() - - val blockReason = chatEvent.blockedReason.uppercase() - if (blockReason != "") { - event.isCanceled = true - loggerFiltered.log("[$blockReason] $message") - loggerAll.log("[$blockReason] $message") - loggerFilteredTypes.getOrPut(blockReason) { LorenzLogger("chat/filter_blocked/$blockReason") } - .log(message) - return - } - - if (!message.startsWith("§f{\"server\":\"")) { - loggerAllowed.log(message) - loggerAll.log("[allowed] $message") - } + } + } + + @SubscribeEvent(receiveCanceled = true) + fun onChatReceive(event: ClientChatReceivedEvent) { + val messageComponent = event.message + val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText) + + val chatEvent = LorenzChatEvent(message, messageComponent) + chatEvent.postAndCatch() + + val blockReason = chatEvent.blockedReason.uppercase() + if (blockReason != "") { + event.isCanceled = true + loggerFiltered.log("[$blockReason] $message") + loggerAll.log("[$blockReason] $message") + loggerFilteredTypes.getOrPut(blockReason) { LorenzLogger("chat/filter_blocked/$blockReason") } + .log(message) + return + } + if (!message.startsWith("§f{\"server\":\"")) { + loggerAllowed.log(message) + loggerAll.log("[allowed] $message") } } }
\ No newline at end of file |