Your First Command
The simplest command requires just the@Command annotation and a sender parameter:
@Command("hello")- Defines the command name that players will type (e.g.,/hello)@Sender CommandSender sender- Receives the command sender (player or console)sender.sendMessage(...)- Sends a message back to whoever executed the command
Adding a Description
Make your command more user-friendly by adding a description that appears in help messages:@Description annotation adds helpful information that appears when players view command help.
Player-Only Commands
Many commands should only be executable by players, not the console:Player instead of CommandSender, Blade automatically ensures only players can execute this command.
Commands with Arguments
Add parameters to accept arguments from the command sender:@Name("target")- Defines the argument name shown in usage messagesPlayer target- Blade automatically parses player names and validates they’re online- Usage:
/teleport <target>
Multiple Arguments
Commands can have multiple arguments of different types:- Players:
Player - Numbers:
int,double,float,long - Text:
String - Materials:
Material(Bukkit) - Custom types via ArgumentProvider
Optional Arguments
Make arguments optional using the@Opt annotation:
/heal- Heals yourself/heal PlayerName- Heals the specified player
Default to Sender
Use@Opt(Opt.Type.SENDER) to automatically use the sender when no argument is provided:
Adding Permissions
Restrict command access with the@Permission annotation:
@Permission("op")- Requires operator status@Permission("console")- Console only@Permission("myplugin.command")- Requires specific permission node
Custom Permission Messages
Next Steps
Now that you understand basic commands, explore more advanced features:- Complex Commands - Flags, ranges, and greedy arguments
- Subcommands - Organize related commands
- Custom Types - Create custom argument providers