aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/features/chat
diff options
context:
space:
mode:
authoringle <inglettronald@gmail.com>2022-10-29 12:12:03 -0500
committeringle <inglettronald@gmail.com>2022-10-29 12:12:03 -0500
commit393d4c8e14730a5c9b31695f722b6de9480508ec (patch)
treef8c9c1143e17e8578cc1567d3a464e219459f69f /src/main/kotlin/dulkirmod/features/chat
parent798b38e5f3579469192916b69427ce46127deead (diff)
downloadDulkirMod-393d4c8e14730a5c9b31695f722b6de9480508ec.tar.gz
DulkirMod-393d4c8e14730a5c9b31695f722b6de9480508ec.tar.bz2
DulkirMod-393d4c8e14730a5c9b31695f722b6de9480508ec.zip
+ abiphone do not disturb
= refactored chatevent code for readability
Diffstat (limited to 'src/main/kotlin/dulkirmod/features/chat')
-rw-r--r--src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt51
-rw-r--r--src/main/kotlin/dulkirmod/features/chat/Bridge.kt46
-rw-r--r--src/main/kotlin/dulkirmod/features/chat/FakeMsg.kt20
-rw-r--r--src/main/kotlin/dulkirmod/features/chat/ThrottleNotif.kt23
4 files changed, 140 insertions, 0 deletions
diff --git a/src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt b/src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt
new file mode 100644
index 0000000..1f922f2
--- /dev/null
+++ b/src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt
@@ -0,0 +1,51 @@
+package dulkirmod.features.chat
+
+import dulkirmod.DulkirMod
+import dulkirmod.config.Config
+import net.minecraft.util.ChatComponentText
+import net.minecraftforge.client.event.ClientChatReceivedEvent
+import net.minecraftforge.client.event.sound.PlaySoundEvent
+import net.minecraftforge.fml.common.eventhandler.EventPriority
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+private val abiphoneFormat = "✆ (\\w+) ✆ ".toRegex()
+private var lastRing: Long = 0
+
+class AbiphoneDND {
+ //BLOCK ABIPHONE SOUNDS
+ @SubscribeEvent(receiveCanceled = false, priority = EventPriority.LOW)
+ fun onSound(event: PlaySoundEvent) {
+ if (!Config.abiDND) return
+ if (System.currentTimeMillis() - lastRing < 5000) {
+ if (event.name == "note.pling" && event.sound.volume == 0.69f && event.sound.pitch == 1.6666666f) {
+ event.isCanceled = true
+ }
+ }
+ }
+
+ companion object {
+ fun handle(event: ClientChatReceivedEvent, unformatted: String) {
+ if (!Config.abiDND) return
+ if (unformatted matches abiphoneFormat) {
+ val matchResult = abiphoneFormat.find(unformatted)
+ event.isCanceled = true;
+ lastRing = System.currentTimeMillis()
+ if (Config.abiCallerID) {
+ DulkirMod.mc.thePlayer.addChatMessage(
+ ChatComponentText(
+ "${DulkirMod.CHAT_PREFIX} §6Call blocked from ${
+ if (Math.random() < .001) "Breefing"
+ else matchResult?.groups?.get(1)?.value
+ }!"
+ )
+ )
+ }
+ }
+ if (unformatted.startsWith("✆ Ring...") && unformatted.endsWith("[PICK UP]")
+ && System.currentTimeMillis() - lastRing < 5000) {
+ event.isCanceled = true;
+ }
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/dulkirmod/features/chat/Bridge.kt b/src/main/kotlin/dulkirmod/features/chat/Bridge.kt
new file mode 100644
index 0000000..f413be8
--- /dev/null
+++ b/src/main/kotlin/dulkirmod/features/chat/Bridge.kt
@@ -0,0 +1,46 @@
+package dulkirmod.features.chat
+
+import dulkirmod.config.Config
+import dulkirmod.utils.Utils
+import net.minecraft.util.ChatComponentText
+import net.minecraft.util.EnumChatFormatting
+import net.minecraftforge.client.event.ClientChatReceivedEvent
+
+object Bridge {
+ 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()
+
+ fun handle(event: ClientChatReceivedEvent) {
+ val message = event.message.unformattedText
+ if (guildFormat matches message && Config.bridgeBot) {
+ val matchResult = guildFormat.find(message)
+ val (prefix, name, playerName) = matchResult!!.destructured
+ if (Utils.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())
+ }
+ }
+
+ // OTHER FORMAT
+ else if (alternateFormat matches message && Config.bridgeBot) {
+ val matchResult = alternateFormat.find(message)
+ val (prefix, name, playerName) = matchResult!!.destructured
+ if (Utils.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
diff --git a/src/main/kotlin/dulkirmod/features/chat/FakeMsg.kt b/src/main/kotlin/dulkirmod/features/chat/FakeMsg.kt
new file mode 100644
index 0000000..f73572e
--- /dev/null
+++ b/src/main/kotlin/dulkirmod/features/chat/FakeMsg.kt
@@ -0,0 +1,20 @@
+package dulkirmod.features.chat
+
+import net.minecraft.client.Minecraft
+import net.minecraft.util.ChatComponentText
+import net.minecraftforge.client.event.ClientChatReceivedEvent
+
+object FakeMsg {
+ fun handle(event: ClientChatReceivedEvent, unformatted: String) {
+ if (unformatted.startsWith("From [MVP++] Dulkir: c:")) {
+ event.isCanceled = true
+ val newst = unformatted.substring("From [MVP++] Dulkir: c:".length)
+ Minecraft.getMinecraft().thePlayer.addChatMessage(ChatComponentText(newst.replace("&", "§")))
+ }
+ if (unformatted.startsWith("From [MVP+] Dulkir: c:")) {
+ event.isCanceled = true
+ val newst = unformatted.substring("From [MVP+] Dulkir: c:".length)
+ Minecraft.getMinecraft().thePlayer.addChatMessage(ChatComponentText(newst.replace("&", "§")))
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/dulkirmod/features/chat/ThrottleNotif.kt b/src/main/kotlin/dulkirmod/features/chat/ThrottleNotif.kt
new file mode 100644
index 0000000..b17f301
--- /dev/null
+++ b/src/main/kotlin/dulkirmod/features/chat/ThrottleNotif.kt
@@ -0,0 +1,23 @@
+package dulkirmod.features.chat
+
+import dulkirmod.DulkirMod
+import dulkirmod.config.Config
+import dulkirmod.utils.Utils
+import net.minecraftforge.client.event.ClientChatReceivedEvent
+
+object ThrottleNotif {
+ private var lastThrottle : Long = 0
+ fun handle(event: ClientChatReceivedEvent, unformatted: String) {
+ if (unformatted == "This menu has been throttled! Please slow down..." && DulkirMod.config.throttleNotifier
+ && Utils.isInDungeons()) {
+ event.isCanceled = true;
+ if (!Config.throttleNotifierSpam && System.currentTimeMillis() - lastThrottle > 3000) {
+ DulkirMod.mc.thePlayer.sendChatMessage("/pc " + DulkirMod.config.customMessage)
+ }
+ else {
+ DulkirMod.mc.thePlayer.sendChatMessage("/pc " + DulkirMod.config.customMessage)
+ }
+ lastThrottle = System.currentTimeMillis()
+ }
+ }
+} \ No newline at end of file