blob: f0a5cb0c01267b8498bac40b6143486e8bb26f8c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
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) {
// This throws an error but still blocks the sound. Not a great solution, but it works for now
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;
}
}
}
}
|