summaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-05-24 18:16:37 +0200
committerLinnea Gräf <nea@nea.moe>2024-05-24 18:16:37 +0200
commit5b68a5f3f716c8d12117b39efba8c4b8d09fcb98 (patch)
tree77fbd5503748073a4cf4968bda4d592d2aebd977 /src/main/kotlin
parentb681f11ea5a72d4ec6a34c2807f6ed781bbd19bc (diff)
downloadultra-notifier-5b68a5f3f716c8d12117b39efba8c4b8d09fcb98.tar.gz
ultra-notifier-5b68a5f3f716c8d12117b39efba8c4b8d09fcb98.tar.bz2
ultra-notifier-5b68a5f3f716c8d12117b39efba8c4b8d09fcb98.zip
Add basic chat commands
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/UltraNotifier.kt2
-rw-r--r--src/main/kotlin/UltraNotifierEntryPoint.kt2
-rw-r--r--src/main/kotlin/commands/Commands.kt50
-rw-r--r--src/main/kotlin/event/ChatGuiLineEvent.kt10
-rw-r--r--src/main/kotlin/event/ChatLineAddedEvent.kt7
-rw-r--r--src/main/kotlin/event/PacketChatLineEvent.kt5
-rw-r--r--src/main/kotlin/event/UltraNotifierEvents.kt8
7 files changed, 76 insertions, 8 deletions
diff --git a/src/main/kotlin/UltraNotifier.kt b/src/main/kotlin/UltraNotifier.kt
index 17798cc..dce1fda 100644
--- a/src/main/kotlin/UltraNotifier.kt
+++ b/src/main/kotlin/UltraNotifier.kt
@@ -1,5 +1,6 @@
package moe.nea.ultranotifier
+import moe.nea.ultranotifier.commands.Commands
import moe.nea.ultranotifier.init.NeaMixinConfig
import java.io.File
@@ -16,6 +17,7 @@ object UltraNotifier {
for (mixinPlugin in NeaMixinConfig.getMixinPlugins()) {
logger.info("Loaded ${mixinPlugin.mixins.size} mixins for ${mixinPlugin.mixinPackage}.")
}
+ Commands.init()
}
val configFolder = File("config/ultra-notifier").also {
diff --git a/src/main/kotlin/UltraNotifierEntryPoint.kt b/src/main/kotlin/UltraNotifierEntryPoint.kt
index 67dd566..42ae064 100644
--- a/src/main/kotlin/UltraNotifierEntryPoint.kt
+++ b/src/main/kotlin/UltraNotifierEntryPoint.kt
@@ -21,7 +21,7 @@ package moe.nea.ultranotifier
//$$}
//#else
import net.fabricmc.api.ModInitializer
-object UltraNotifierEntryPoint : ModInitializer {
+class UltraNotifierEntryPoint : ModInitializer {
override fun onInitialize() {
UltraNotifier.onStartup()
}
diff --git a/src/main/kotlin/commands/Commands.kt b/src/main/kotlin/commands/Commands.kt
new file mode 100644
index 0000000..75047cd
--- /dev/null
+++ b/src/main/kotlin/commands/Commands.kt
@@ -0,0 +1,50 @@
+package moe.nea.ultranotifier.commands
+
+import com.mojang.brigadier.CommandDispatcher
+import com.mojang.brigadier.builder.LiteralArgumentBuilder
+import moe.nea.ultranotifier.UltraNotifier
+import moe.nea.ultranotifier.event.UltraNotifierEvents
+import net.minecraft.text.Text
+
+interface CustomSource {
+ fun sendFeedback(text: Text)
+}
+
+
+typealias UltraCommandSource =
+//#if FORGE
+//$$ CustomSource
+//#else
+ net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
+
+//#endif
+
+
+fun literalText(string: String): Text =
+//#if MC >= 11400
+ Text.literal(string)
+//#else
+//$$ net.minecraft.util.ChatComponentText(string)
+//#endif
+
+object Commands {
+ fun registerAll(dispatcher: CommandDispatcher<UltraCommandSource>) {
+ dispatcher.register(LiteralArgumentBuilder.literal<UltraCommandSource>("hello")
+ .executes {
+ it.source.sendFeedback(literalText("Hello World"))
+ 0
+ })
+ }
+
+ fun init() {
+ UltraNotifierEvents.register(this)
+//#if FORGE
+//$$
+//#else
+ net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback.EVENT.register { dispatcher, registryAccess ->
+ registerAll(dispatcher)
+ }
+//#endif
+ UltraNotifier.logger.info("Initialized command subsystem")
+ }
+}
diff --git a/src/main/kotlin/event/ChatGuiLineEvent.kt b/src/main/kotlin/event/ChatGuiLineEvent.kt
new file mode 100644
index 0000000..e37d31f
--- /dev/null
+++ b/src/main/kotlin/event/ChatGuiLineEvent.kt
@@ -0,0 +1,10 @@
+package moe.nea.ultranotifier.event
+
+import net.minecraft.text.Text
+
+class ChatGuiLineEvent(val component: Text) : UltraEvent() {
+ val string = component.string
+ override fun toString(): String {
+ return "ChatLineAddedEvent($string)"
+ }
+}
diff --git a/src/main/kotlin/event/ChatLineAddedEvent.kt b/src/main/kotlin/event/ChatLineAddedEvent.kt
deleted file mode 100644
index 0460f83..0000000
--- a/src/main/kotlin/event/ChatLineAddedEvent.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-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/PacketChatLineEvent.kt b/src/main/kotlin/event/PacketChatLineEvent.kt
new file mode 100644
index 0000000..2d5887c
--- /dev/null
+++ b/src/main/kotlin/event/PacketChatLineEvent.kt
@@ -0,0 +1,5 @@
+package moe.nea.ultranotifier.event
+
+import net.minecraft.text.Text
+
+class PacketChatLineEvent(val component: Text) : UltraEvent()
diff --git a/src/main/kotlin/event/UltraNotifierEvents.kt b/src/main/kotlin/event/UltraNotifierEvents.kt
index 8c8fb13..34d1769 100644
--- a/src/main/kotlin/event/UltraNotifierEvents.kt
+++ b/src/main/kotlin/event/UltraNotifierEvents.kt
@@ -15,6 +15,14 @@ object UltraNotifierEvents {
eventBus.post(event)
return event
}
+
+ fun register(obj: Any) {
+//#if FORGE
+//$$ eventBus.register(obj)
+//#else
+ eventBus.subscribe(obj)
+//#endif
+ }
}