Skip to main content

commands

The builder every command must go through (Architecture › Rule 3), and the generator behind the Commands page. Source in libs/commands/.

Defining a command​

Commands.define("role")
.description("Shows or changes a player's role.")
.usage("/role get <player>", "/role set <player> <role>")
.example("/role get Alice", "/role set Alice moderator")
.permission("shatterveil.role.manage")
.setup(cmd -> { /* cmd.addSyntax(...) */ })
.register(ctx); // -> ctx.registerCommand(command, doc); undone on disable
  • build / register throw IllegalArgumentException when the description, usage, examples or permission is missing (CommandDoc validates them), so an undocumented command can't exist.
  • The permission is enforced for you. The command's condition is Permissions.require(node) from the permissions library: console always passes; players need a role that holds the node.
  • The default executor prints the usage lines, so wrong usage shows the same text as the docs.
  • Registration goes through the ModuleContext, so the command is unregistered when the module is disabled.

The command reference​

CommandDocs.render(docs) produces docs/commands.md in the server repo from every CommandDoc registered by the kernel and the modules.

  • ./gradlew :server:generateCommandDocs rewrites it.
  • server's CommandDocsTest fails the build when the committed file is stale, so it can't drift from the code.
  • The Commands page on this site is a copy of that file, updated by hand when it changes.