aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/features/chat
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/dulkirmod/features/chat')
-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