aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-07-23 21:47:02 -0500
committeringlettronald <inglettronald@gmail.com>2023-07-23 21:47:02 -0500
commitc56059b6c9d28d17d82de090c5a0b9d9382cb82c (patch)
treeaa1f6b2c4798502c6f2ccafff788eb04f17c8379 /src/main/kotlin
parentc36dd88ff83ff09d5941d6772b5eefff0cd10665 (diff)
downloadDulkirMod-Fabric-c56059b6c9d28d17d82de090c5a0b9d9382cb82c.tar.gz
DulkirMod-Fabric-c56059b6c9d28d17d82de090c5a0b9d9382cb82c.tar.bz2
DulkirMod-Fabric-c56059b6c9d28d17d82de090c5a0b9d9382cb82c.zip
Chat stacking with lots of refactor
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/com/dulkirfabric/Registrations.kt8
-rw-r--r--src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt13
-rw-r--r--src/main/kotlin/com/dulkirfabric/events/chat/ChatEvents.kt14
-rw-r--r--src/main/kotlin/com/dulkirfabric/events/chat/ChatReceivedEvent.kt7
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/ArachneFeatures.kt4
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt4
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/chat/BridgeBotFormatter.kt6
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/chat/ChatStacking.kt40
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/ActionBarUtil.kt4
9 files changed, 77 insertions, 23 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt
index fdace3c..7e68f90 100644
--- a/src/main/kotlin/com/dulkirfabric/Registrations.kt
+++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt
@@ -3,12 +3,13 @@ package com.dulkirfabric
import com.dulkirfabric.DulkirModFabric.EVENT_BUS
import com.dulkirfabric.commands.*
import com.dulkirfabric.events.*
-import com.dulkirfabric.events.chat.ChatReceivedEvent
+import com.dulkirfabric.events.chat.ChatEvents
import com.dulkirfabric.events.chat.ModifyCommandEvent
import com.dulkirfabric.events.chat.OverlayReceivedEvent
import com.dulkirfabric.features.*
import com.dulkirfabric.features.chat.AbiPhoneDND
import com.dulkirfabric.features.chat.BridgeBotFormatter
+import com.dulkirfabric.features.chat.ChatStacking
import com.dulkirfabric.hud.ActionBarHudReplacements
import com.dulkirfabric.hud.SpeedOverlay
import com.dulkirfabric.util.ActionBarUtil
@@ -75,6 +76,7 @@ object Registrations {
EVENT_BUS.subscribe(SpeedOverlay)
EVENT_BUS.subscribe(ActionBarUtil)
EVENT_BUS.subscribe(ActionBarHudReplacements)
+ EVENT_BUS.subscribe(ChatStacking)
}
fun registerEvents() {
@@ -86,13 +88,13 @@ object Registrations {
}
ClientReceiveMessageEvents.ALLOW_GAME.register { message, overlay ->
if (!overlay)
- return@register !ChatReceivedEvent(message).post()
+ return@register !ChatEvents.AllowChat(message).post()
return@register true
}
ClientReceiveMessageEvents.MODIFY_GAME.register { message, overlay ->
if (overlay)
return@register OverlayReceivedEvent(message).post()
- return@register message
+ return@register ChatEvents.ModifyChat(message).post()
}
ClientSendMessageEvents.MODIFY_COMMAND.register { command ->
diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
index a095c23..d310be4 100644
--- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
+++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
@@ -126,10 +126,16 @@ class DulkirConfig {
entryBuilder.mkToggle(Text.literal("Arachne Boss Spawn Timer"), configOptions::arachneSpawnTimer)
)
general.addEntry(
- entryBuilder.mkToggle(Text.literal("Convert Action Bar to HUD elements"), configOptions::hudifyActionBar, tooltip = Text.literal("This converts Mana/Health/Def/Stacks as HUD elements"))
+ entryBuilder.mkToggle(Text.literal("Convert Action Bar to HUD elements"), configOptions::hudifyActionBar,
+ tooltip = Text.literal("This converts Mana/Health/Def/Stacks as HUD elements"))
)
general.addEntry(
- entryBuilder.mkToggle(Text.literal("Include EHP in def HUD element"), configOptions::showEHP, tooltip = Text.literal("Must have Action Bar HUD elements Enabled"))
+ entryBuilder.mkToggle(Text.literal("Include EHP in def HUD element"), configOptions::showEHP,
+ tooltip = Text.literal("Must have Action Bar HUD elements Enabled"))
+ )
+ general.addEntry(
+ entryBuilder.mkToggle(Text.literal("Hide Held Item Tooltips"), configOptions::hideHeldItemTooltip,
+ tooltip = Text.literal("This is for the pesky overlay that pops up on switching items"))
)
val shortcuts = builder.getOrCreateCategory(Text.literal("Shortcuts"))
@@ -275,7 +281,8 @@ class DulkirConfig {
var bridgeNameColor: Int = Formatting.GOLD.colorValue!!,
val positions: MutableMap<String, HudElement.Positioning> = mutableMapOf(),
var hudifyActionBar: Boolean = true,
- var showEHP: Boolean = false
+ var showEHP: Boolean = false,
+ var hideHeldItemTooltip: Boolean = false
)
@Serializable
diff --git a/src/main/kotlin/com/dulkirfabric/events/chat/ChatEvents.kt b/src/main/kotlin/com/dulkirfabric/events/chat/ChatEvents.kt
new file mode 100644
index 0000000..2f57085
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/events/chat/ChatEvents.kt
@@ -0,0 +1,14 @@
+package com.dulkirfabric.events.chat
+
+import com.dulkirfabric.events.base.CancellableEvent
+import com.dulkirfabric.events.base.ModifyTextEvent
+import net.minecraft.text.Text
+
+class ChatEvents {
+ data class
+ AllowChat(val message: Text) : CancellableEvent()
+
+ data class
+ ModifyChat(val message: Text): ModifyTextEvent(message)
+
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/events/chat/ChatReceivedEvent.kt b/src/main/kotlin/com/dulkirfabric/events/chat/ChatReceivedEvent.kt
deleted file mode 100644
index 4c268ab..0000000
--- a/src/main/kotlin/com/dulkirfabric/events/chat/ChatReceivedEvent.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.dulkirfabric.events.chat
-
-import com.dulkirfabric.events.base.CancellableEvent
-import net.minecraft.text.Text
-
-data class
-ChatReceivedEvent(val message: Text): CancellableEvent() \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/features/ArachneFeatures.kt b/src/main/kotlin/com/dulkirfabric/features/ArachneFeatures.kt
index f573736..1257db8 100644
--- a/src/main/kotlin/com/dulkirfabric/features/ArachneFeatures.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/ArachneFeatures.kt
@@ -2,7 +2,7 @@ package com.dulkirfabric.features
import com.dulkirfabric.config.DulkirConfig
import com.dulkirfabric.events.WorldRenderLastEvent
-import com.dulkirfabric.events.chat.ChatReceivedEvent
+import com.dulkirfabric.events.chat.ChatEvents
import com.dulkirfabric.util.TablistUtils
import com.dulkirfabric.util.TextUtils
import com.dulkirfabric.util.TextUtils.unformattedString
@@ -45,7 +45,7 @@ object ArachneFeatures {
}
@EventHandler
- fun onChat(event: ChatReceivedEvent) {
+ fun onChat(event: ChatEvents.AllowChat) {
if (!DulkirConfig.configOptions.arachneSpawnTimer) return
if (TablistUtils.persistentInfo.area != "Spider's Den") return
val str = event.message.unformattedString.trim()
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<ChatLog>()
+
+ @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
diff --git a/src/main/kotlin/com/dulkirfabric/util/ActionBarUtil.kt b/src/main/kotlin/com/dulkirfabric/util/ActionBarUtil.kt
index 4970ba8..b5397b5 100644
--- a/src/main/kotlin/com/dulkirfabric/util/ActionBarUtil.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/ActionBarUtil.kt
@@ -28,12 +28,12 @@ object ActionBarUtil {
val sb = StringBuilder()
var stackFlag = false
event.message.formattedString().split(splitRegex).forEach {
- healthRegex.matchEntire(TextUtils.stripColorCodes(it)) ?.let { result ->
+ healthRegex.matchEntire(TextUtils.stripColorCodes(it))?.let { result ->
healthInt = result.groupValues[1].replace(",", "").toInt()
healthStr = it
return@forEach
}
- defRegex.matchEntire(TextUtils.stripColorCodes(it)) ?.let { result ->
+ defRegex.matchEntire(TextUtils.stripColorCodes(it))?.let { result ->
defInt = result.groupValues[1].replace(",", "").toInt()
defStr = it.replace(" Defense", "")
return@forEach