From f3f6da9f50edfbe9ed3be42fa16146210e60fbf3 Mon Sep 17 00:00:00 2001 From: inglettronald Date: Sat, 10 Jun 2023 21:38:38 -0500 Subject: yeah I'm not documenting this today --- .../com/dulkirfabric/commands/DynamicKeyCommand.kt | 48 ++++++++++++++++++++++ .../com/dulkirfabric/commands/RestArgumentType.kt | 12 ++++++ 2 files changed, 60 insertions(+) create mode 100644 src/main/kotlin/com/dulkirfabric/commands/DynamicKeyCommand.kt create mode 100644 src/main/kotlin/com/dulkirfabric/commands/RestArgumentType.kt (limited to 'src/main/kotlin/com/dulkirfabric/commands') diff --git a/src/main/kotlin/com/dulkirfabric/commands/DynamicKeyCommand.kt b/src/main/kotlin/com/dulkirfabric/commands/DynamicKeyCommand.kt new file mode 100644 index 0000000..f253957 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/commands/DynamicKeyCommand.kt @@ -0,0 +1,48 @@ +package com.dulkirfabric.commands + +import com.dulkirfabric.util.TextUtils +import com.mojang.brigadier.CommandDispatcher +import com.mojang.brigadier.arguments.StringArgumentType +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import com.mojang.brigadier.builder.RequiredArgumentBuilder +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource +import net.minecraft.command.CommandRegistryAccess + +object DynamicKeyCommand { + var command = "" + fun register(dispatcher: CommandDispatcher, registryAccess: CommandRegistryAccess) { + dispatcher.register( + LiteralArgumentBuilder.literal("dk") + .executes { context -> + TextUtils.info("§6Usage: /dk set ") + TextUtils.info("§6For more information about this command, run /dk help") + return@executes 0 + } + .then( + LiteralArgumentBuilder.literal("set") + .then( + RequiredArgumentBuilder.argument("command", RestArgumentType) + .executes { context -> + command = StringArgumentType.getString(context, "command") + command = command.removePrefix("/") + TextUtils.info("§6§lCommand Registered: §7$command") + return@executes 1 + } + ) + ) + .then( + LiteralArgumentBuilder.literal("help") + .executes { + TextUtils.info("§6§lDynamic Keybind Info") + TextUtils.info("§7 - There's a keybind setting inside your Dulkir Config you can use in order" + + " to make a chat macro for a particular in game command. This only works for commands.", prefix = false) + TextUtils.info("§7 - Usage: /dk set ", prefix = false) + TextUtils.info("§7 (i made this cuz I have a mouse button that i use for a bunch of different useful " + + "actions depending upon what I'm doing, so don't worry if this feature doesn't apply to you lol)", prefix = false) + return@executes 2 + } + ) + ) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/commands/RestArgumentType.kt b/src/main/kotlin/com/dulkirfabric/commands/RestArgumentType.kt new file mode 100644 index 0000000..a6f13ac --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/commands/RestArgumentType.kt @@ -0,0 +1,12 @@ +package com.dulkirfabric.commands + +import com.mojang.brigadier.StringReader +import com.mojang.brigadier.arguments.ArgumentType + +object RestArgumentType: ArgumentType { + override fun parse(reader: StringReader): String { + val remaining = reader.remaining + reader.cursor += remaining.length + return remaining + } +} \ No newline at end of file -- cgit