summaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-02-22 22:05:15 +0100
committerLinnea Gräf <nea@nea.moe>2024-02-22 22:06:01 +0100
commitaef074886b587745bd814fe965d55e7b4cf11a07 (patch)
treeacc62b9aaf9f95bdce17a85683c42cbec93fe800 /src/main/kotlin/moe/nea
parente8196b0b5e02ec21f75109ab7aba8d48220c8d05 (diff)
downloadKowalski-aef074886b587745bd814fe965d55e7b4cf11a07.tar.gz
Kowalski-aef074886b587745bd814fe965d55e7b4cf11a07.tar.bz2
Kowalski-aef074886b587745bd814fe965d55e7b4cf11a07.zip
Add event cancellation watcher
Diffstat (limited to 'src/main/kotlin/moe/nea')
-rw-r--r--src/main/kotlin/moe/nea/kowalski/ExampleMod.kt22
-rw-r--r--src/main/kotlin/moe/nea/kowalski/Kowalski.kt51
-rw-r--r--src/main/kotlin/moe/nea/kowalski/mixin/MixinGuiMainMenu.java16
3 files changed, 51 insertions, 38 deletions
diff --git a/src/main/kotlin/moe/nea/kowalski/ExampleMod.kt b/src/main/kotlin/moe/nea/kowalski/ExampleMod.kt
deleted file mode 100644
index a622a6c..0000000
--- a/src/main/kotlin/moe/nea/kowalski/ExampleMod.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package moe.nea.kowalski
-
-import net.minecraft.client.Minecraft
-import net.minecraft.init.Blocks
-import net.minecraftforge.fml.common.Mod
-import net.minecraftforge.fml.common.event.FMLInitializationEvent
-
-@Mod(modid = "kowalski", useMetadata = true)
-class ExampleMod {
- @Mod.EventHandler
- fun init(event: FMLInitializationEvent) {
- try {
- val resource: net.minecraft.client.resources.IResource = Minecraft.getMinecraft().getResourceManager()
- .getResource(net.minecraft.util.ResourceLocation("test:test.txt"))
- org.apache.commons.io.IOUtils.copy(resource.getInputStream(), java.lang.System.out)
- } catch (e: java.io.IOException) {
- throw java.lang.RuntimeException(e)
- }
-
- println("Dirt: ${Blocks.dirt.unlocalizedName}")
- }
-}
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<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)
+ }
+
+
+}
diff --git a/src/main/kotlin/moe/nea/kowalski/mixin/MixinGuiMainMenu.java b/src/main/kotlin/moe/nea/kowalski/mixin/MixinGuiMainMenu.java
deleted file mode 100644
index 4ddc1b4..0000000
--- a/src/main/kotlin/moe/nea/kowalski/mixin/MixinGuiMainMenu.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package moe.nea.kowalski.mixin;
-
-import net.minecraft.client.gui.GuiMainMenu;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-
-@Mixin(GuiMainMenu.class)
-public class MixinGuiMainMenu {
-
- @Inject(method = "initGui", at = @At("HEAD"))
- public void onInitGui(CallbackInfo ci) {
- System.out.println("Hello from Main Menu!");
- }
-}