diff options
author | ingle <inglettronald@gmail.com> | 2022-10-03 23:51:37 -0500 |
---|---|---|
committer | ingle <inglettronald@gmail.com> | 2022-10-03 23:51:37 -0500 |
commit | a29f8090ff819b100c9a1725faff1241e562c4f3 (patch) | |
tree | afb46e82787dff31b6548f0b578c3c672b7f4f46 /src/main/kotlin/dulkirmod/events | |
parent | 2092d19741295699b49c9aeaee4993cc15797556 (diff) | |
download | DulkirMod-a29f8090ff819b100c9a1725faff1241e562c4f3.tar.gz DulkirMod-a29f8090ff819b100c9a1725faff1241e562c4f3.tar.bz2 DulkirMod-a29f8090ff819b100c9a1725faff1241e562c4f3.zip |
Expanded Bridge Support to fit "name: message" format
Diffstat (limited to 'src/main/kotlin/dulkirmod/events')
-rw-r--r-- | src/main/kotlin/dulkirmod/events/ChatEvent.kt | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main/kotlin/dulkirmod/events/ChatEvent.kt b/src/main/kotlin/dulkirmod/events/ChatEvent.kt index f1a4bef..e034996 100644 --- a/src/main/kotlin/dulkirmod/events/ChatEvent.kt +++ b/src/main/kotlin/dulkirmod/events/ChatEvent.kt @@ -10,7 +10,8 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class ChatEvent { - private val guildFormat = "^(§2Guild|§3Officer) > (?:\\S+ )?([\\w§]{3,18})(?: §[a-z]\\[[A-Z]+])?§f: (\\w+) > .+".toRegex() + private val guildFormat = "^(§2Guild|§3Officer) > (?:\\S+ )?([\\w§]{3,18})(?: §[a-z0-9]\\[[A-Z]+])?§f: (\\w+) > .+".toRegex() + private val alternateFormat = "^(§2Guild|§3Officer) > (?:\\S+ )?([\\w§]{3,18})(?: §[a-z0-9]\\[[A-Z]+])?§f: (\\w+): .+".toRegex() @SubscribeEvent(receiveCanceled = true, priority = EventPriority.LOW) fun onChat(event: ClientChatReceivedEvent) { if (event.type == 2.toByte()) { @@ -40,5 +41,21 @@ class ChatEvent { ).setChatStyle(event.message.siblings[1].chatStyle.createShallowCopy()) } } + + // OTHER FORMAT + else if (alternateFormat matches message && Config.bridgeBot) { + val matchResult = alternateFormat.find(message) + val (prefix, name, playerName) = matchResult!!.destructured + if (stripColorCodes(name.lowercase()) == Config.botName.lowercase()) { + val newPrefix = if (prefix == "§2Guild") "§2Bridge" else "§3Bridge" + val color = if (Config.bridgeColor == 16) "§z" else EnumChatFormatting.values()[Config.bridgeColor] + event.message.siblings[0] = ChatComponentText( + "$newPrefix > $color$playerName§f: " + ) + event.message.siblings[1] = ChatComponentText( + event.message.siblings[1].unformattedText.replace("$playerName: ", "") + ).setChatStyle(event.message.siblings[1].chatStyle.createShallowCopy()) + } + } } }
\ No newline at end of file |