summaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/kowalski/Kowalski.kt
blob: 2bede19b5d2195e60fa342ace77d186028cf126c (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
package moe.nea.kowalski

import net.minecraftforge.client.ClientCommandHandler
import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.eventhandler.Event
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@Mod(modid = "kowalski", useMetadata = true)
class Kowalski {

    companion object {
        val watchedEvents = mutableSetOf<String>()

        @JvmStatic
        fun eventIsBeingCancelled(event: Event) {
            if (event.javaClass.simpleName !in watchedEvents) {
                return
            }
            val interestingStack = Thread.currentThread()
                .stackTrace
                .dropWhile { it.className.startsWith("java.lang.") }
                .dropWhile { it.className.startsWith("moe.nea.kowalski.") }
                .drop(1)
            KowalskiCommand.chat(
                "§c§k!!!§c RED ALERT §k!!!§c\n" +
                        "AN EVENT HAS BEEN CANCELLED\n" +
                        "§c=================\n" +
                        "§e${interestingStack.joinToString("\n§e")}\n" +
                        "§c================="
            )
        }
    }


    @SubscribeEvent
    fun cancelMessages(event: ClientChatReceivedEvent) {
        if (event.message.unformattedText.contains("verboten"))
            event.isCanceled = true
    }

    @Mod.EventHandler
    fun init(event: FMLInitializationEvent) {
        ClientCommandHandler.instance.registerCommand(KowalskiCommand)
        MinecraftForge.EVENT_BUS.register(this)
    }


}