aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-09-15 15:37:24 +0200
committerLorenz <lo.scherf@gmail.com>2022-09-15 15:37:24 +0200
commit5503770c826201ab40e141937e6cdd2b0e9788f6 (patch)
tree378d86127037f9a291925d8065a752565f5439dc /src/main/java/at/hannibal2/skyhanni/data
parent7036145597c0059433c02a047bbf59096ed1d244 (diff)
downloadskyhanni-5503770c826201ab40e141937e6cdd2b0e9788f6.tar.gz
skyhanni-5503770c826201ab40e141937e6cdd2b0e9788f6.tar.bz2
skyhanni-5503770c826201ab40e141937e6cdd2b0e9788f6.zip
fixed skytils dungeon timers not working
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
new file mode 100644
index 000000000..38a50da6e
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
@@ -0,0 +1,56 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.events.LorenzActionBarEvent
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+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
+
+class ChatManager {
+
+ private val loggerAll = LorenzLogger("chat/filter_all")
+ private val loggerFiltered = LorenzLogger("chat/filter_blocked")
+ private val loggerAllowed = LorenzLogger("chat/filter_allowed")
+ private val loggerFilteredTypes = mutableMapOf<String, LorenzLogger>()
+
+ @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
+ fun onActionBarPacket(event: PacketEvent.ReceiveEvent) {
+ val packet = event.packet
+ if (packet !is S02PacketChat) return
+ val messageComponent = packet.chatComponent
+
+ val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText)
+ if (packet.type.toInt() == 2) {
+ val actionBarEvent = LorenzActionBarEvent(message)
+ actionBarEvent.postAndCatch()
+ }
+ }
+
+ @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