From 94de4c68e0b29d6032cfbfecb23263d5c706b64f Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Tue, 7 Apr 2026 18:00:56 +0900 Subject: feat: Add subcommand alias nodes --- .../paper/command/core/LunaticCommand.kt | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'platform-paper/src') diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommand.kt index 1fe4835..429a9c9 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommand.kt @@ -133,6 +133,30 @@ abstract class LunaticCommand( return result.toBrigadierResult() } + /** + * Creates alias nodes for a subcommand. + * Each alias gets the same children, executor, and permission requirement as the primary node. + * Brigadier automatically provides tab completion for all registered literal nodes. + * + * @param primary The primary subcommand builder + * @param aliases The alias names for the subcommand + * @return A list containing the primary builder followed by alias builders + */ + protected fun withAliases( + primary: LiteralArgumentBuilder, + aliases: List, + ): List> { + if (aliases.isEmpty()) return listOf(primary) + return listOf(primary) + + aliases.map { alias -> + val aliasBuilder = Commands.literal(alias) + primary.arguments.forEach { aliasBuilder.then(it) } + primary.command?.let { aliasBuilder.executes(it) } + aliasBuilder.requires(primary.requirement) + aliasBuilder + } + } + /** * Applies permission checks to a subcommand builder based on method-level @Permission annotation. * Used for subcommands that use build() instead of buildCommand(). -- cgit v1.2.1