Command Framework
Command argument basics
CommandArguments is an utility class for Command Framework and includes the basic parameters related Bukkit commands and bunch of useful methods to improve your code.
Basic Methods
// We have created a basic command named "example"
@Command(
name = "example"
)
public void exampleCommandMethod(CommandArguments arguments) {
// To get command sender use CommandArguments#getSender method
CommandSender sender = arguments.getSender();
// To check who is the sender
if (arguments.isSenderPlayer()) {
// now sender is player
} else {
// and now sender is console
}
// To get as Bukkit's command use CommandArguments#getCommand method
// After that you can be able to get command's name, description, permission, etc.
org.bukkit.command.Command command = arguments.getCommand();
// To get label of command use CommandArguments#getLabel method
String label = arguments.getLabel();
// To get arguments of command use CommandArguments#getArguments() method
// and don't forget these arguments is not all the parts of default arguments
// because they'll be splitted after sub-command parts
String[] args = arguments.getArguments();
// To get specific argument without receiving argument array
// There is no exception during this operation but also don't forget
// that method can be null if index is out of bounds.
String firstArgument = arguments.getArgument(0);
// To get arguments array is empty or not without receiving array.
boolean isArgsEmpty = arguments.isArgumentsEmpty();
// To send message to command sender without receivingits object
arguments.sendMessage("Hey there!");
// To check if command sender has permission without receiving sender object
if (arguments.hasPermission("command.framework") {
// sender has the given permission
} else {
// sender has not the given permission
}
// To get arguments length without receiving string array
int argumentsLength = arguments.getLength();
}Useful Methods
Registering Commands
Create an CommandFramework object using the constructor then register the commands using CommandFramework#registerCommands method, then framework will register all the methods that have Command or Completer annotations and CommandArguments parameter as a command in the class.
Creating Command
Before creating commands, you must create a method body, then annotate the Command and don't forget to add CommandArguments as a parameter to your method. If you don't know what are the attributes that you can change, take a look at Commands page.
Creating Sub Command
Sub commands are separated by dots. For example if command is "one.two.three" then "one" will be the first part of the command, "two" is the second and "three" is the third. So the command will be "one two three <other arguments if there are>" and the command arguments will be splitted after sub commands like if the command is "one two three four five" then the command arguments will be [four, five].
Creating Tab Completions
Before creating a tab completion, create a method body with List<String> return type or any other implementation of it but List is recommended and do not use the raw type. Then annotate the Completer and don't forget to add CommandArguments as a parameter to your method. Tab completions also support sub commands as the normal commands too. For example command's name can be "command.subcommand" and command will be "command subcommand <completions>"
Creating Commands Without Arguments
Creating Commands With Cooldowns
Example Usage
Last updated