From aef074886b587745bd814fe965d55e7b4cf11a07 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 22 Feb 2024 22:05:15 +0100 Subject: Add event cancellation watcher --- src/main/kotlin/moe/nea/kowalski/Kowalski.kt | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/kotlin/moe/nea/kowalski/Kowalski.kt (limited to 'src/main/kotlin/moe/nea/kowalski/Kowalski.kt') diff --git a/src/main/kotlin/moe/nea/kowalski/Kowalski.kt b/src/main/kotlin/moe/nea/kowalski/Kowalski.kt new file mode 100644 index 0000000..2bede19 --- /dev/null +++ b/src/main/kotlin/moe/nea/kowalski/Kowalski.kt @@ -0,0 +1,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() + + @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) + } + + +} -- cgit