From c56059b6c9d28d17d82de090c5a0b9d9382cb82c Mon Sep 17 00:00:00 2001 From: inglettronald Date: Sun, 23 Jul 2023 21:47:02 -0500 Subject: Chat stacking with lots of refactor --- .../com/dulkirfabric/features/chat/AbiPhoneDND.kt | 4 +-- .../features/chat/BridgeBotFormatter.kt | 6 ++-- .../com/dulkirfabric/features/chat/ChatStacking.kt | 40 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 src/main/kotlin/com/dulkirfabric/features/chat/ChatStacking.kt (limited to 'src/main/kotlin/com/dulkirfabric/features/chat') diff --git a/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt b/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt index c000010..623c7b1 100644 --- a/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt +++ b/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt @@ -1,8 +1,8 @@ package com.dulkirfabric.features.chat import com.dulkirfabric.config.DulkirConfig -import com.dulkirfabric.events.chat.ChatReceivedEvent import com.dulkirfabric.events.PlaySoundEvent +import com.dulkirfabric.events.chat.ChatEvents import com.dulkirfabric.util.TextUtils import com.dulkirfabric.util.TextUtils.unformattedString import meteordevelopment.orbit.EventHandler @@ -24,7 +24,7 @@ object AbiPhoneDND { } @EventHandler - fun handle(event: ChatReceivedEvent) { + fun handle(event: ChatEvents.AllowChat) { if (!DulkirConfig.configOptions.abiPhoneDND) return val unformatted = event.message.unformattedString if (unformatted matches abiPhoneFormat && !unformatted.contains("Elle") && !unformatted.contains("Dean")) { diff --git a/src/main/kotlin/com/dulkirfabric/features/chat/BridgeBotFormatter.kt b/src/main/kotlin/com/dulkirfabric/features/chat/BridgeBotFormatter.kt index f956791..e584431 100644 --- a/src/main/kotlin/com/dulkirfabric/features/chat/BridgeBotFormatter.kt +++ b/src/main/kotlin/com/dulkirfabric/features/chat/BridgeBotFormatter.kt @@ -1,19 +1,17 @@ package com.dulkirfabric.features.chat import com.dulkirfabric.config.DulkirConfig -import com.dulkirfabric.events.chat.ChatReceivedEvent +import com.dulkirfabric.events.chat.ChatEvents import com.dulkirfabric.util.TextUtils -import com.dulkirfabric.util.Utils import meteordevelopment.orbit.EventHandler import net.minecraft.text.Style import net.minecraft.text.Text -import net.minecraft.util.Formatting object BridgeBotFormatter { private val bridgeRegex: Regex = "^(§2Guild|§3Officer) > (?:\\S+ )?([\\w§]{3,18})(?: §[a-z0-9][[A-Z]+])?§f: ([^>]+)(?: >| »|:) (.+)".toRegex() @EventHandler - fun onChat(event: ChatReceivedEvent) { + fun onChat(event: ChatEvents.AllowChat) { if (!DulkirConfig.configOptions.bridgeFormatter) return val message = event.message.string diff --git a/src/main/kotlin/com/dulkirfabric/features/chat/ChatStacking.kt b/src/main/kotlin/com/dulkirfabric/features/chat/ChatStacking.kt new file mode 100644 index 0000000..02d1914 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/features/chat/ChatStacking.kt @@ -0,0 +1,40 @@ +package com.dulkirfabric.features.chat + +import com.dulkirfabric.DulkirModFabric.mc +import com.dulkirfabric.events.LongUpdateEvent +import com.dulkirfabric.events.chat.ChatEvents +import com.dulkirfabric.util.ScoreBoardUtils.formattedString +import meteordevelopment.orbit.EventHandler +import net.minecraft.text.Text + +object ChatStacking { + + data class ChatLog(var timestamp: Long, val message: Text, var frequency: Int) + + private var chatLogs = mutableSetOf() + + @EventHandler + fun modifyChat(event: ChatEvents.ModifyChat) { + chatLogs.forEach { curMsg -> + if (curMsg.message.string.equals(event.message.string)) { + curMsg.timestamp = System.currentTimeMillis() + curMsg.frequency++ + mc.inGameHud.chatHud.messages.removeIf { msg -> + msg.content.string == curMsg.message.string + && mc.inGameHud.ticks - msg.creationTick >= 1200 + } + mc.inGameHud.chatHud.refresh() + event.setReturnValue(Text.literal("${curMsg.message.formattedString()} §7(${curMsg .frequency})")) + return + } + } + chatLogs.add(ChatLog(System.currentTimeMillis(), event.message, 1)) + } + + @EventHandler + fun cullLogs(event: LongUpdateEvent) { + chatLogs.removeIf { + System.currentTimeMillis() - it.timestamp >= 60000 + } + } +} \ No newline at end of file -- cgit