From b681f11ea5a72d4ec6a34c2807f6ed781bbd19bc Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Tue, 21 May 2024 22:02:50 +0200 Subject: Add subscriber annotation --- .../ultranotifier/mixin/ChatHudMessageAdded.java | 6 +-- src/main/kotlin/UltraNotifierEvents.kt | 53 ---------------------- src/main/kotlin/event/ChatLineAddedEvent.kt | 7 +++ src/main/kotlin/event/UltraEvent.kt | 37 +++++++++++++++ src/main/kotlin/event/UltraNotifierEvents.kt | 20 ++++++++ src/main/kotlin/event/UltraSubscribe.kt | 8 ++++ versions/mapping-1.14.4-forge-1.8.9.txt | 2 + 7 files changed, 77 insertions(+), 56 deletions(-) delete mode 100644 src/main/kotlin/UltraNotifierEvents.kt create mode 100644 src/main/kotlin/event/ChatLineAddedEvent.kt create mode 100644 src/main/kotlin/event/UltraEvent.kt create mode 100644 src/main/kotlin/event/UltraNotifierEvents.kt create mode 100644 src/main/kotlin/event/UltraSubscribe.kt diff --git a/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java b/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java index a9323d7..b6c013f 100644 --- a/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java +++ b/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java @@ -1,7 +1,7 @@ package moe.nea.ultranotifier.mixin; -import moe.nea.ultranotifier.ChatLineAddedEvent; -import moe.nea.ultranotifier.UltraNotifierEvents; +import moe.nea.ultranotifier.event.ChatLineAddedEvent; +import moe.nea.ultranotifier.event.UltraNotifierEvents; import net.minecraft.client.gui.hud.ChatHud; //#if MC > 11404 import net.minecraft.client.gui.hud.MessageIndicator; @@ -37,7 +37,7 @@ public class ChatHudMessageAdded { //#endif CallbackInfo ci ) { - if (UltraNotifierEvents.post(new ChatLineAddedEvent()).isCancelled()) { + if (UltraNotifierEvents.post(new ChatLineAddedEvent(message)).isCancelled()) { ci.cancel(); } } diff --git a/src/main/kotlin/UltraNotifierEvents.kt b/src/main/kotlin/UltraNotifierEvents.kt deleted file mode 100644 index d47a0be..0000000 --- a/src/main/kotlin/UltraNotifierEvents.kt +++ /dev/null @@ -1,53 +0,0 @@ -package moe.nea.ultranotifier - -object UltraNotifierEvents { - val eventBus = -//#if FORGE -//$$ net.minecraftforge.common.MinecraftForge.EVENT_BUS -//#else - me.bush.eventbus.bus.EventBus { UltraNotifier.logger.warn("EventBus: $it") } -//#endif - @JvmStatic - fun post(event: T): T { - UltraNotifier.logger.info("Posting $event") - eventBus.post(event) - return event - } -} - -abstract class UltraEvent : -//#if FORGE -//$$ net.minecraftforge.eventbus.api.Event() -//#else - me.bush.eventbus.event.Event() -//#endif -{ -//#if FORGE -//$$ override fun isCancelable(): Boolean { -//$$ return this.isCancellable() -//$$ } -//$$ fun isCancelled(): Boolean { -//$$ return isCanceled() -//$$ } -//$$ fun setCancelled(value: Boolean) { -//$$ setCanceled(value) -//$$ } -//#else - override -//#endif - - fun isCancellable(): Boolean { - return true - } - -//#if FORGE == 0 - override -//#endif - fun cancel() { - setCancelled(true) - } - -} - - -class ChatLineAddedEvent() : UltraEvent() diff --git a/src/main/kotlin/event/ChatLineAddedEvent.kt b/src/main/kotlin/event/ChatLineAddedEvent.kt new file mode 100644 index 0000000..0460f83 --- /dev/null +++ b/src/main/kotlin/event/ChatLineAddedEvent.kt @@ -0,0 +1,7 @@ +package moe.nea.ultranotifier.event + +import net.minecraft.text.Text + +class ChatLineAddedEvent(val component: Text) : UltraEvent() { + val string = component.string +} diff --git a/src/main/kotlin/event/UltraEvent.kt b/src/main/kotlin/event/UltraEvent.kt new file mode 100644 index 0000000..42fa4f2 --- /dev/null +++ b/src/main/kotlin/event/UltraEvent.kt @@ -0,0 +1,37 @@ +package moe.nea.ultranotifier.event + +abstract class UltraEvent : +//#if FORGE +//$$ net.minecraftforge.eventbus.api.Event() +//#else + me.bush.eventbus.event.Event() +//#endif +{ +//#if FORGE +//$$ override fun isCancelable(): Boolean { +//$$ return this.isCancellable() +//$$ } +//$$ fun isCancelled(): Boolean { +//$$ return isCanceled() +//$$ } +//$$ fun setCancelled(value: Boolean) { +//$$ setCanceled(value) +//$$ } +//#else + override +//#endif + + fun isCancellable(): Boolean { + return true + } + +//#if FORGE == 0 + override +//#endif + fun cancel() { + setCancelled(true) + } + +} + + diff --git a/src/main/kotlin/event/UltraNotifierEvents.kt b/src/main/kotlin/event/UltraNotifierEvents.kt new file mode 100644 index 0000000..8c8fb13 --- /dev/null +++ b/src/main/kotlin/event/UltraNotifierEvents.kt @@ -0,0 +1,20 @@ +package moe.nea.ultranotifier.event + +import moe.nea.ultranotifier.UltraNotifier + +object UltraNotifierEvents { + val eventBus = +//#if FORGE +//$$ net.minecraftforge.common.MinecraftForge.EVENT_BUS +//#else + me.bush.eventbus.bus.EventBus { UltraNotifier.logger.warn("EventBus: $it") } +//#endif + @JvmStatic + fun post(event: T): T { + UltraNotifier.logger.info("Posting $event") + eventBus.post(event) + return event + } +} + + diff --git a/src/main/kotlin/event/UltraSubscribe.kt b/src/main/kotlin/event/UltraSubscribe.kt new file mode 100644 index 0000000..d0b37ef --- /dev/null +++ b/src/main/kotlin/event/UltraSubscribe.kt @@ -0,0 +1,8 @@ +package moe.nea.ultranotifier.event + +typealias UltraSubscribe = +//#if FORGE +//$$ net.minecraftforge.eventbus.api.SubscribeEvent +//#else + me.bush.eventbus.annotation.EventListener +//#endif diff --git a/versions/mapping-1.14.4-forge-1.8.9.txt b/versions/mapping-1.14.4-forge-1.8.9.txt index f25eb1e..cdd8783 100644 --- a/versions/mapping-1.14.4-forge-1.8.9.txt +++ b/versions/mapping-1.14.4-forge-1.8.9.txt @@ -1,3 +1,5 @@ net.minecraft.client.gui.NewChatGui net.minecraft.client.gui.GuiNewChat net.minecraft.util.text.ITextComponent net.minecraft.util.IChatComponent +net.minecraft.util.text.ITextComponent getString() getUnformattedText() net.minecraftforge.eventbus.api.Event net.minecraftforge.fml.common.eventhandler.Event +net.minecraftforge.eventbus.api.SubscribeEvent net.minecraftforge.fml.common.eventhandler.SubscribeEvent -- cgit