Commands
A Kotlin builder on Paper's command API: typed arguments, subcommands, validators and tab completion.
Docs updated · What changed
Register commands in onEnable. They go through Paper's command system, so no plugin.yml entry is needed. Arguments are parsed first; the next word then picks a subcommand.
Registering a commandLink to this section
CommandUtil.registerCommand(this, "island") {
aliases = mutableListOf("is")
description = "Island commands"
playerOnly = true
action { sender, _ -> openIslandMenu(sender as Player) } // "/island" with no subcommand
subcommand("invite") {
arg("player", ArgType.PLAYER)
action { sender, args -> invite(sender as Player, args.player("player")) }
}
subcommand("setsize") {
permission = "island.admin" // hidden from tab completion without it
arg("owner", ArgType.OFFLINE_PLAYER)
arg("size", ArgType.INT) {
validate({ _, v -> v in 50..500 }) { MessageUtil.send(it, "&cSize must be 50-500") }
}
arg("reason", ArgType.TEXT) { optional = true } // rest of the line
action { sender, args ->
setSize(args.offlinePlayer("owner"), args.int("size"), args.stringOrNull("reason"))
}
}
}Argument typesLink to this section
| Arg type | Value |
|---|---|
STRING | one word |
TEXT | the rest of the line; must be the last argument |
INT, LONG, DOUBLE | numbers |
BOOLEAN | true/false, yes/no, on/off |
PLAYER | an online player by exact name (Bedrock names include the Floodgate prefix) |
OFFLINE_PLAYER | anyone who joined before; never blocks on a web lookup |
Custom typesLink to this section
Extend ArgType and read the value with args.get<T>(name).
object SkillArg : ArgType<Skill>("skill") {
override fun parse(raw: String) = Skill.byId(raw)
override fun suggestions() = Skill.ids
}OptionsLink to this section
- Per argument:
optional,validate(check, onFail),suggest { },onInvalid { sender, raw -> }. - Per command:
permission,playerOnly,noPermissionMessage,playerOnlyMessage,onMissingArgs,onUnknownSubcommand.