aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/features/chat
diff options
context:
space:
mode:
authoringlettronald <71849533+inglettronald@users.noreply.github.com>2023-02-13 20:10:06 -0600
committerGitHub <noreply@github.com>2023-02-13 20:10:06 -0600
commit7df778d6ac01a6d350608a5962b9344493444ebc (patch)
tree69abbc662cbb3a325f05aa4fbcd2f0fa0ff37cd6 /src/main/kotlin/dulkirmod/features/chat
parent1c27ca0e7586c27de7ddd51723b5bf7b0ab50230 (diff)
parent3985b5f7417571f4a1e90eefa287af053b740e69 (diff)
downloadDulkirMod-7df778d6ac01a6d350608a5962b9344493444ebc.tar.gz
DulkirMod-7df778d6ac01a6d350608a5962b9344493444ebc.tar.bz2
DulkirMod-7df778d6ac01a6d350608a5962b9344493444ebc.zip
Merge pull request #10 from IlmarsXd/master
Cleaned up some code and fixed AbiphoneDND log spam
Diffstat (limited to 'src/main/kotlin/dulkirmod/features/chat')
-rw-r--r--src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt72
-rw-r--r--src/main/kotlin/dulkirmod/features/chat/FakeMsg.kt15
-rw-r--r--src/main/kotlin/dulkirmod/features/chat/ThrottleNotif.kt11
-rw-r--r--src/main/kotlin/dulkirmod/features/chat/VanquisherTrigger.kt4
4 files changed, 44 insertions, 58 deletions
diff --git a/src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt b/src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt
index 9212bbd..a6a0ab6 100644
--- a/src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt
+++ b/src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt
@@ -1,8 +1,7 @@
package dulkirmod.features.chat
-import dulkirmod.DulkirMod
import dulkirmod.config.Config
-import net.minecraft.util.ChatComponentText
+import dulkirmod.utils.TextUtils
import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.client.event.sound.PlaySoundEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
@@ -12,44 +11,35 @@ 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) {
- // This throws an error but still blocks the sound. Not a great solution, but it works for now
- try {
- event.isCanceled = true
- } catch (ignored: IllegalArgumentException) {
- }
- }
- }
- }
+ //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.result = null
+ }
+ }
+ }
- 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;
- }
- }
- }
+ 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) {
+ val blocked = if (Math.random() < .001) "Breefing"
+ else matchResult?.groups?.get(1)?.value
+ TextUtils.info("§6Call blocked from $blocked!")
+ }
+ }
+ 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/FakeMsg.kt b/src/main/kotlin/dulkirmod/features/chat/FakeMsg.kt
index f73572e..e1b618f 100644
--- a/src/main/kotlin/dulkirmod/features/chat/FakeMsg.kt
+++ b/src/main/kotlin/dulkirmod/features/chat/FakeMsg.kt
@@ -1,20 +1,15 @@
package dulkirmod.features.chat
-import net.minecraft.client.Minecraft
-import net.minecraft.util.ChatComponentText
+import dulkirmod.utils.TextUtils
import net.minecraftforge.client.event.ClientChatReceivedEvent
object FakeMsg {
+ private val dulkirRegex = "From \\[MVP(\\+|\\+\\+)] Dulkir: c:".toRegex()
fun handle(event: ClientChatReceivedEvent, unformatted: String) {
- if (unformatted.startsWith("From [MVP++] Dulkir: c:")) {
+ if (dulkirRegex.matches(unformatted)) {
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("&", "§")))
+ val message = unformatted.replace(dulkirRegex, "").replace("&", "§")
+ TextUtils.info(message, false)
}
}
} \ 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
index c572db0..f6a90eb 100644
--- a/src/main/kotlin/dulkirmod/features/chat/ThrottleNotif.kt
+++ b/src/main/kotlin/dulkirmod/features/chat/ThrottleNotif.kt
@@ -2,6 +2,7 @@ package dulkirmod.features.chat
import dulkirmod.DulkirMod
import dulkirmod.config.Config
+import dulkirmod.utils.TextUtils
import dulkirmod.utils.Utils
import net.minecraftforge.client.event.ClientChatReceivedEvent
@@ -11,11 +12,11 @@ object ThrottleNotif {
if (unformatted == "This menu has been throttled! Please slow down..." && DulkirMod.config.throttleNotifier
&& Utils.isInDungeons()
) {
- event.isCanceled = true;
- if (!Config.throttleNotifierSpam && System.currentTimeMillis() - lastThrottle > 8000) {
- DulkirMod.mc.thePlayer.sendChatMessage("/pc " + DulkirMod.config.customMessage)
- } else {
- DulkirMod.mc.thePlayer.sendChatMessage("/pc " + DulkirMod.config.customMessage)
+ event.isCanceled = true
+ if (!Config.throttleNotifierSpam && System.currentTimeMillis() - lastThrottle > 8000) {
+ TextUtils.sendPartyChatMessage(DulkirMod.config.customMessage)
+ } else if (Config.throttleNotifierSpam) {
+ TextUtils.sendPartyChatMessage(DulkirMod.config.customMessage)
}
lastThrottle = System.currentTimeMillis()
}
diff --git a/src/main/kotlin/dulkirmod/features/chat/VanquisherTrigger.kt b/src/main/kotlin/dulkirmod/features/chat/VanquisherTrigger.kt
index c7d4349..d607df2 100644
--- a/src/main/kotlin/dulkirmod/features/chat/VanquisherTrigger.kt
+++ b/src/main/kotlin/dulkirmod/features/chat/VanquisherTrigger.kt
@@ -1,13 +1,13 @@
package dulkirmod.features.chat
-import dulkirmod.DulkirMod
import dulkirmod.config.Config
+import dulkirmod.utils.TextUtils
object VanquisherTrigger {
fun handle(message: String) {
if (!Config.vanqBroadcast) return
if (message == "A Vanquisher is spawning nearby!") {
- DulkirMod.mc.thePlayer.sendChatMessage("/patcher sendcoords")
+ TextUtils.sendMessage("/patcher sendcoords")
}
}
} \ No newline at end of file