diff options
author | ingle <inglettronald@gmail.com> | 2022-10-29 12:12:03 -0500 |
---|---|---|
committer | ingle <inglettronald@gmail.com> | 2022-10-29 12:12:03 -0500 |
commit | 393d4c8e14730a5c9b31695f722b6de9480508ec (patch) | |
tree | f8c9c1143e17e8578cc1567d3a464e219459f69f | |
parent | 798b38e5f3579469192916b69427ce46127deead (diff) | |
download | DulkirMod-393d4c8e14730a5c9b31695f722b6de9480508ec.tar.gz DulkirMod-393d4c8e14730a5c9b31695f722b6de9480508ec.tar.bz2 DulkirMod-393d4c8e14730a5c9b31695f722b6de9480508ec.zip |
+ abiphone do not disturb
= refactored chatevent code for readability
-rw-r--r-- | src/main/kotlin/dulkirmod/DulkirMod.kt | 4 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/config/Config.kt | 19 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/events/ChatEvent.kt | 76 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/events/caller.txt | 4 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt | 51 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/features/chat/Bridge.kt | 46 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/features/chat/FakeMsg.kt | 20 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/features/chat/ThrottleNotif.kt | 23 |
8 files changed, 176 insertions, 67 deletions
diff --git a/src/main/kotlin/dulkirmod/DulkirMod.kt b/src/main/kotlin/dulkirmod/DulkirMod.kt index 0291226..8f1be1c 100644 --- a/src/main/kotlin/dulkirmod/DulkirMod.kt +++ b/src/main/kotlin/dulkirmod/DulkirMod.kt @@ -4,6 +4,7 @@ import dulkirmod.command.* import dulkirmod.config.Config import dulkirmod.events.ChatEvent import dulkirmod.features.* +import dulkirmod.features.chat.AbiphoneDND import dulkirmod.utils.ContainerNameUtil import dulkirmod.utils.TitleUtils import kotlinx.coroutines.CoroutineScope @@ -56,7 +57,7 @@ class DulkirMod { @Mod.EventHandler fun onInit(event: FMLInitializationEvent) { config.init() - // REGISTER EVENTS HERE + // REGISTER Classes and such HERE MinecraftForge.EVENT_BUS.register(this) MinecraftForge.EVENT_BUS.register(ChatEvent()) MinecraftForge.EVENT_BUS.register(NametagCleaner) @@ -66,6 +67,7 @@ class DulkirMod { MinecraftForge.EVENT_BUS.register(Croesus()) MinecraftForge.EVENT_BUS.register(ContainerNameUtil()) MinecraftForge.EVENT_BUS.register(DungeonLeap()) + MinecraftForge.EVENT_BUS.register(AbiphoneDND()) keyBinds.forEach(ClientRegistry::registerKeyBinding) } diff --git a/src/main/kotlin/dulkirmod/config/Config.kt b/src/main/kotlin/dulkirmod/config/Config.kt index d300b85..f52a085 100644 --- a/src/main/kotlin/dulkirmod/config/Config.kt +++ b/src/main/kotlin/dulkirmod/config/Config.kt @@ -14,13 +14,29 @@ object Config : Vigilant(File("./config/dulkirmod/config.toml"), "DulkirMod", so @Property( type = PropertyType.SWITCH, name = "Hide Enchant Rune Particles", - description = "ugly ass", + description = "ugly go bye-bye", category = "General" ) var hideEnchantRune = false @Property( type = PropertyType.SWITCH, + name = "Abiphone Do-Not-Disturb", + description = "Detects incoming calls and mutes ring audio for like 5 seconds. \nWorks as long as u don't lag particularly hard at the same time you're being called.", + category = "General" + ) + var abiDND = false + + @Property( + type = PropertyType.SWITCH, + name = "Abiphone Caller ID", + description = "If DND is on, Still give the player a 1 liner to tell them who is calling", + category = "General" + ) + var abiCallerID = false + + @Property( + type = PropertyType.SWITCH, name = "Hide Healer fairy", description = "Probably disable when not in dungeons for now. Will fix later.", category = "Dungeons" @@ -469,6 +485,7 @@ object Config : Vigilant(File("./config/dulkirmod/config.toml"), "DulkirMod", so addDependency("bestiaryNotifVol", "bestiaryAlertSounds") addDependency("demoVolume", "bestiaryAlertSounds") addDependency("highlightLeapName", "highlightLeap") + addDependency("abiCallerID", "abiDND") setCategoryDescription( "Custom Animations", diff --git a/src/main/kotlin/dulkirmod/events/ChatEvent.kt b/src/main/kotlin/dulkirmod/events/ChatEvent.kt index 3bddaea..9820ecc 100644 --- a/src/main/kotlin/dulkirmod/events/ChatEvent.kt +++ b/src/main/kotlin/dulkirmod/events/ChatEvent.kt @@ -1,83 +1,37 @@ package dulkirmod.events -import dulkirmod.DulkirMod -import dulkirmod.config.Config -import dulkirmod.utils.Utils +import dulkirmod.features.chat.AbiphoneDND +import dulkirmod.features.chat.Bridge +import dulkirmod.features.chat.FakeMsg +import dulkirmod.features.chat.ThrottleNotif import dulkirmod.utils.Utils.stripColorCodes -import net.minecraft.util.ChatComponentText -import net.minecraft.util.EnumChatFormatting import net.minecraftforge.client.event.ClientChatReceivedEvent 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-z0-9]\\[[A-Z]+])?§f: (\\w+) > .+".toRegex() - private val alternateFormat = "^(§2Guild|§3Officer) > (?:\\S+ )?([\\w§]{3,18})(?: §[a-z0-9]\\[[A-Z]+])?§f: (\\w+): .+".toRegex() - private var lastThrottle : Long = 0 - private var lastRing : Long = 0 + /** + * This is mostly the way it is to avoid having to run strip color codes a bunch of times + * for each message. Not sure if it even matters but whatever + */ @SubscribeEvent(receiveCanceled = true, priority = EventPriority.LOW) fun onChat(event: ClientChatReceivedEvent) { if (event.type == 2.toByte()) { return } + val unformatted = stripColorCodes(event.message.unformattedText) // THROTTLE NOTIFIER - val unformatted = stripColorCodes(event.message.unformattedText) - if (unformatted == "This menu has been throttled! Please slow down..." && DulkirMod.config.throttleNotifier - && Utils.isInDungeons()) { - event.isCanceled = true; - if (!Config.throttleNotifierSpam && System.currentTimeMillis() - lastThrottle > 5000) { - DulkirMod.mc.thePlayer.sendChatMessage("/pc " + DulkirMod.config.customMessage) - } - else { - DulkirMod.mc.thePlayer.sendChatMessage("/pc " + DulkirMod.config.customMessage) - } - lastThrottle = System.currentTimeMillis() - } + ThrottleNotif.handle(event, unformatted) // BRIDGE BOT STUFF - CLICKABLE LINKS! - val message = event.message.unformattedText - if (guildFormat matches message && Config.bridgeBot) { - val matchResult = guildFormat.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()) - } - } - - // 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()) - } - } + Bridge.handle(event) // DO NOT DISTURB FOR ABIPHONE - if (unformatted.equals("✆ \\w+ ✆".toRegex())) { - DulkirMod.mc.thePlayer.addChatMessage( - ChatComponentText("${DulkirMod.CHAT_PREFIX} §6Call blocked!") - ) - event.isCanceled = true; - lastRing = System.currentTimeMillis() - } - if (unformatted.startsWith("✆ Ring...") && unformatted.endsWith("[PICK UP]") && System.currentTimeMillis() - lastRing < 4000) - event.isCanceled = true; + AbiphoneDND.handle(event, unformatted) + + // FAKE MESSAGE SENDER (DULKIR ONLY) + FakeMsg.handle(event,unformatted) } }
\ No newline at end of file diff --git a/src/main/kotlin/dulkirmod/events/caller.txt b/src/main/kotlin/dulkirmod/events/caller.txt deleted file mode 100644 index 75ec9e9..0000000 --- a/src/main/kotlin/dulkirmod/events/caller.txt +++ /dev/null @@ -1,4 +0,0 @@ -✆ Aranya ✆ -§a✆ Ring... §2§l[PICK UP] -§a✆ Ring... Ring... §2§l[PICK UP] -§a✆ Ring... Ring... Ring... §2§l[PICK UP]
\ No newline at end of file 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 |