diff options
author | Linnea Gräf <nea@nea.moe> | 2024-05-24 18:16:37 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-05-24 18:16:37 +0200 |
commit | 5b68a5f3f716c8d12117b39efba8c4b8d09fcb98 (patch) | |
tree | 77fbd5503748073a4cf4968bda4d592d2aebd977 /src/main/kotlin/commands/Commands.kt | |
parent | b681f11ea5a72d4ec6a34c2807f6ed781bbd19bc (diff) | |
download | ultra-notifier-5b68a5f3f716c8d12117b39efba8c4b8d09fcb98.tar.gz ultra-notifier-5b68a5f3f716c8d12117b39efba8c4b8d09fcb98.tar.bz2 ultra-notifier-5b68a5f3f716c8d12117b39efba8c4b8d09fcb98.zip |
Add basic chat commands
Diffstat (limited to 'src/main/kotlin/commands/Commands.kt')
-rw-r--r-- | src/main/kotlin/commands/Commands.kt | 50 |
1 files changed, 50 insertions, 0 deletions
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") + } +} |