aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/events/ChatEvent.kt
blob: 03f8dd898da85c0e11ea6f98dbaaa88e638f91ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package dulkirmod.events

import dulkirmod.DulkirMod
import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class ChatEvent {
    @SubscribeEvent(receiveCanceled = true, priority = EventPriority.LOW)
    fun onChat(event: ClientChatReceivedEvent) {
        if (event.type == 2.toByte()) {
            return
        }
        val unformatted = stripColorCodes(event.message.unformattedText)
        if (unformatted == "This menu has been throttled! Please slow down..." && DulkirMod.config.throttleNotifier) {
            event.isCanceled = true;
            DulkirMod.mc.thePlayer.sendChatMessage("/pc " + DulkirMod.config.customMessage)
        }
    }
    private fun stripColorCodes(string: String): String {
        return string.replace("§.".toRegex(), "")
    }
}