aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlmarsXd <ilmars500@gmail.com>2023-02-08 16:18:21 +0200
committerIlmarsXd <ilmars500@gmail.com>2023-02-08 16:18:21 +0200
commit929e414c2db6de6d58af637d2b5f4dd3c5a90d9d (patch)
tree01082021987e2cab83296c6d5508fe536b53dae5
parent1c27ca0e7586c27de7ddd51723b5bf7b0ab50230 (diff)
downloadDulkirMod-929e414c2db6de6d58af637d2b5f4dd3c5a90d9d.tar.gz
DulkirMod-929e414c2db6de6d58af637d2b5f4dd3c5a90d9d.tar.bz2
DulkirMod-929e414c2db6de6d58af637d2b5f4dd3c5a90d9d.zip
fixed AbiphoneDND log spam, use TextUtils for messages
-rw-r--r--src/main/kotlin/dulkirmod/features/chat/AbiphoneDND.kt72
1 files changed, 31 insertions, 41 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