To create a new command, extend the SimpleCommand abstract class. You must implement the onCommand() method, which contains the actual logic for your command. The execute() method is handled by the base class, which automatically manages permissions, minimum argument checks, cooldowns, and error handling.
Key Lifecycle & Features
- Registration: Use
.register() to add the command to Bukkit. You can use .register(true, unregisterOldAliases) to handle potential conflicts with existing commands. - Arguments: Access command arguments via the
args array and the command sender via the sender object (both updated dynamically during execution). - Help System: If
autoHandleHelp is true (default), running the command with help or ? will automatically display your usage message. You can customize this by overriding getMultilineUsageMessage(). - Cooldowns: You can set a cooldown in seconds using
setCooldownSeconds(int). Players can bypass this if they have the permission specified by setCooldownBypassPermission(String).
public class MyCommand extends SimpleCommand {
public MyCommand() {
// Use '|' to separate the main label from aliases
super("test|t|testcmd");
setCooldownSeconds(10);
setMinArguments(1);
}
@Override
protected void onCommand() {
// Your logic here
tellSuccess("Command executed successfully!");
}
@Override
protected String[] getMultilineUsageMessage() {
return new String[] {
"Usage: /test <name>",
"<name> - The name of the player to target"
};
}
}