-
-
Notifications
You must be signed in to change notification settings - Fork 0
Defining Commands
Every command starts with a class that extends CustomCommand.
@Command("example")
public final class ExampleCommand extends CustomCommand {
}Declares the command name and aliases.
@Command({"warp", "warps"})
public final class WarpCommand extends CustomCommand {
}Declares a base permission for the whole command.
@Command("warp")
@Permission("example.warp")
public final class WarpCommand extends CustomCommand {
}If the sender lacks this permission, the framework stops before selecting a handler.
Defines the root handler for the command.
@Default
public void defaultCommand(CommandSender sender) {
sender.sendMessage("Use /warp teleport <player>");
}Defines one or more subcommand labels handled by a method.
@SubCommand("teleport")
public void teleport(CommandSender sender, Player target) {
}Multiple values are allowed:
@SubCommand({"delete", "remove"})
public void delete(CommandSender sender, String warpName) {
}Multi-word subcommands are also supported:
@SubCommand({"set public", "set private"})
public void setVisibility(CommandSender sender) {
}Adds a permission requirement only to that handler:
@SubCommand("teleport")
@Permission("example.warp.teleport")
public void teleport(CommandSender sender, Player target) {
}Defines a fallback for unmatched subcommands:
@Unknown(false)
public void unknown(CommandSender sender) {
sender.sendMessage("Unknown subcommand.");
}If @Unknown(true) is used, the same method is also exposed as a help subcommand.
@Unknown(true)
public void help(CommandSender sender) {
sender.sendMessage("/warp teleport <player>");
}You can also protect that generated help subcommand with a specific permission:
@Unknown(value = true, helpPermission = "example.warp.help")
public void help(CommandSender sender) {
}A valid handler method follows this layout:
- first parameter = sender type
- remaining parameters = parsed command arguments
Supported sender types:
CommandSenderPlayerConsoleCommandSender
Any other first parameter causes a runtime failure during command setup.
In larger plugins, command sets often use patterns like:
- player-only subcommands
- optional trailing arguments
- explicit manual help through
@Unknown(false) - class-level base permissions with method-level special permissions
@Command("mail")
@Permission("example.mail")
public final class MailCommand extends CustomCommand {
@Default
public void defaultCommand(CommandSender sender) {
sender.sendMessage("/mail send <player> <message>");
}
@SubCommand("send")
@Permission("example.mail.send")
public void send(
Player sender,
@Name("player") Player target,
@Join @Name("message") String message
) {
target.sendMessage(sender.getName() + ": " + message);
}
@Unknown(true)
public void unknown(CommandSender sender) {
sender.sendMessage("Unknown subcommand.");
}
}