From a84da715497215848797719fe528c2f5c1d4aed3 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sun, 24 Mar 2024 00:43:16 +0100 Subject: Add ordered waypoints (ColeWeight compat) --- src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt') diff --git a/src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt b/src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt index 5710245..1d1f8d3 100644 --- a/src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt +++ b/src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2023 Linnea Gräf + * SPDX-FileCopyrightText: 2024 Linnea Gräf * * SPDX-License-Identifier: GPL-3.0-or-later */ @@ -12,6 +13,7 @@ import net.minecraft.command.CommandRegistryAccess import moe.nea.firmament.commands.CaseInsensitiveLiteralCommandNode import moe.nea.firmament.commands.DefaultSource import moe.nea.firmament.commands.literal +import moe.nea.firmament.commands.thenLiteral data class CommandEvent( val dispatcher: CommandDispatcher, @@ -20,6 +22,20 @@ data class CommandEvent( ) : FirmamentEvent() { companion object : FirmamentEventBus() + /** + * Register subcommands to `/firm`. For new top level commands use [CommandEvent]. Cannot be used to register + * subcommands to other commands. + */ + data class SubCommand( + val builder: CaseInsensitiveLiteralCommandNode.Builder, + ) : FirmamentEvent() { + companion object : FirmamentEventBus() + + fun subcommand(name: String, block: CaseInsensitiveLiteralCommandNode.Builder.() -> Unit) { + builder.thenLiteral(name, block) + } + } + fun deleteCommand(name: String) { dispatcher.root.children.removeIf { it.name.equals(name, ignoreCase = false) } serverCommands?.root?.children?.removeIf { it.name.equals(name, ignoreCase = false) } -- cgit