BasicCommand interface and programmatic registration, while legacy plugins can still use the Command class.
Paper plugins using
paper-plugin.yml cannot declare commands in YAML. You must register commands programmatically using JavaPlugin.registerCommand().BasicCommand Interface (Recommended)
TheBasicCommand interface provides a simple, Bukkit-style approach to creating commands.
Creating a BasicCommand
Fromio.papermc.paper.command.brigadier.BasicCommand:
1
Implement BasicCommand
Create a class implementing
BasicCommand:2
Register the Command
Register your command in the plugin’s From
onEnable() method:JavaPlugin.java:374-436, the registerCommand() methods:CommandSourceStack
TheCommandSourceStack (package: io.papermc.paper.command.brigadier.CommandSourceStack) provides context for command execution:
Command Class (Legacy)
For advanced use cases, you can extend theCommand class directly.
Creating a Command
Fromorg.bukkit.command.Command:
Tab Completion
Provide suggestions for command arguments:BasicCommand Tab Completion
Dynamic Tab Completion
Permission Checking
BasicCommand Permissions
Command Class Permissions
Fromorg.bukkit.command.Command:175-225:
Command Aliases
Register multiple aliases for a command:Aliases will not override already existing commands (except namespaced ones). The main command label will override existing commands.
Subcommands
Implement subcommands by parsing the first argument:Lifecycle Event Registration
Alternatively, register commands via lifecycle events:Best Practices
-
Validate input:
-
Check sender type:
-
Use permissions:
-
Provide tab completion:
-
Handle errors gracefully: