summaryrefslogtreecommitdiff
path: root/platform-paper/src
diff options
context:
space:
mode:
authorSho Sakuma <me@m1sk9.dev>2026-04-07 18:00:56 +0900
committerSho Sakuma <me@m1sk9.dev>2026-04-07 18:00:56 +0900
commit94de4c68e0b29d6032cfbfecb23263d5c706b64f (patch)
tree63792f32a8ac15f5c653f6a552c7deefb7103ba4 /platform-paper/src
parentaf6e6e13a7da5dbcccdd24c45f9da63cda57df21 (diff)
downloadLunaticChat-94de4c68e0b29d6032cfbfecb23263d5c706b64f.tar.gz
LunaticChat-94de4c68e0b29d6032cfbfecb23263d5c706b64f.tar.bz2
LunaticChat-94de4c68e0b29d6032cfbfecb23263d5c706b64f.zip
feat: Add subcommand alias nodes
Diffstat (limited to 'platform-paper/src')
-rw-r--r--platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommand.kt24
1 files changed, 24 insertions, 0 deletions
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
@@ -134,6 +134,30 @@ abstract class LunaticCommand(
}
/**
+ * 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<CommandSourceStack>,
+ aliases: List<String>,
+ ): List<LiteralArgumentBuilder<CommandSourceStack>> {
+ 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().
*