-
-
Notifications
You must be signed in to change notification settings - Fork 4
Command arguments
Berke Akçen edited this page Jan 20, 2024
·
12 revisions
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. Don't forget to add this parameter to your method because if you don't add it then the system will state it as normal Java method and not going to register it as a command and also not going to send any warn message so be careful.
// 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
}
// sender has not the given permission
}
// To get arguments length without receiving string array
int argumentsLength = arguments.getArgumentsLength();
}