Package org.bukkit.command
Class Command
java.lang.Object
org.bukkit.command.Command
- Direct Known Subclasses:
- BukkitCommand,- FormattedCommandAlias,- MultipleCommandAlias,- PluginCommand
Represents a Command, which executes various tasks upon user input
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidbroadcastCommandMessage(CommandSender source, String message) static voidbroadcastCommandMessage(CommandSender source, String message, boolean sendToSource) abstract booleanexecute(CommandSender sender, String commandLabel, String[] args) Executes the command, returning its successReturns a list of active aliases of this commandGets a brief description of this commandgetLabel()Returns the label for this commandgetName()Returns the name of this commandGets the permission required by users to be able to perform this commandDeprecated.permission messages have not worked for player-executed commands since 1.13 as clients without permission to execute a command are unaware of its existence and therefore will not send an unknown command execution to the server.getUsage()Gets an example usage of this commandbooleanReturns the current registered state of this commandbooleanregister(CommandMap commandMap) Registers this command to a CommandMap.setAliases(List<String> aliases) Sets the list of aliases to request on registration for this command.setDescription(String description) Sets a brief description of this command.booleanSets the label of this command.booleanSets the name of this command.voidsetPermission(String permission) Sets the permission required by users to be able to perform this commandsetPermissionMessage(String permissionMessage) Deprecated.permission messages have not worked for player-executed commands since 1.13 as clients without permission to execute a command are unaware of its existence and therefore will not send an unknown command execution to the server.Sets the example usage of this commandtabComplete(CommandSender sender, String alias, String[] args) Executed on tab completion for this command, returning a list of options the player can tab through.tabComplete(CommandSender sender, String alias, String[] args, Location location) Executed on tab completion for this command, returning a list of options the player can tab through.booleantestPermission(CommandSender target) Tests the givenCommandSenderto see if they can perform this command.booleantestPermissionSilent(CommandSender target) Tests the givenCommandSenderto see if they can perform this command.toString()booleanunregister(CommandMap commandMap) Unregisters this command from the passed CommandMap applying any outstanding changes
- 
Field Details- 
description
- 
usageMessage
- 
timings
 
- 
- 
Constructor Details- 
Command
- 
Command
 
- 
- 
Method Details- 
executepublic abstract boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) Executes the command, returning its success- Parameters:
- sender- Source object which is executing this command
- commandLabel- The alias of the command used
- args- All arguments passed to the command, split via ' '
- Returns:
- true if the command was successful, otherwise false
 
- 
tabComplete@NotNull public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException Executed on tab completion for this command, returning a list of options the player can tab through.- Parameters:
- sender- Source object which is executing this command
- alias- the alias being used
- args- All arguments passed to the command, split via ' '
- Returns:
- a list of tab-completions for the specified arguments. This will never be null. List may be immutable.
- Throws:
- IllegalArgumentException- if sender, alias, or args is null
 
- 
tabComplete@NotNull public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args, @Nullable Location location) throws IllegalArgumentException Executed on tab completion for this command, returning a list of options the player can tab through.- Parameters:
- sender- Source object which is executing this command
- alias- the alias being used
- args- All arguments passed to the command, split via ' '
- location- The position looked at by the sender, or null if none
- Returns:
- a list of tab-completions for the specified arguments. This will never be null. List may be immutable.
- Throws:
- IllegalArgumentException- if sender, alias, or args is null
 
- 
getNameReturns the name of this command- Returns:
- Name of this command
 
- 
setNameSets the name of this command.May only be used before registering the command. Will return true if the new name is set, and false if the command has already been registered. - Parameters:
- name- New command name
- Returns:
- returns true if the name change happened instantly or false if the command was already registered
 
- 
getPermissionGets the permission required by users to be able to perform this command- Returns:
- Permission name, or null if none
 
- 
setPermissionSets the permission required by users to be able to perform this command- Parameters:
- permission- Permission name or null
 
- 
testPermissionTests the givenCommandSenderto see if they can perform this command.If they do not have permission, they will be informed that they cannot do this. - Parameters:
- target- User to test
- Returns:
- true if they can use it, otherwise false
 
- 
testPermissionSilentTests the givenCommandSenderto see if they can perform this command.No error is sent to the sender. - Parameters:
- target- User to test
- Returns:
- true if they can use it, otherwise false
 
- 
getLabelReturns the label for this command- Returns:
- Label of this command
 
- 
setLabelSets the label of this command.May only be used before registering the command. Will return true if the new name is set, and false if the command has already been registered. - Parameters:
- name- The command's name
- Returns:
- returns true if the name change happened instantly or false if the command was already registered
 
- 
registerRegisters this command to a CommandMap. Once called it only allows changes the registered CommandMap- Parameters:
- commandMap- the CommandMap to register this command to
- Returns:
- true if the registration was successful (the current registered CommandMap was the passed CommandMap or null) false otherwise
 
- 
unregisterUnregisters this command from the passed CommandMap applying any outstanding changes- Parameters:
- commandMap- the CommandMap to unregister
- Returns:
- true if the unregistration was successful (the current registered CommandMap was the passed CommandMap or null) false otherwise
 
- 
isRegisteredpublic boolean isRegistered()Returns the current registered state of this command- Returns:
- true if this command is currently registered false otherwise
 
- 
getAliasesReturns a list of active aliases of this command- Returns:
- List of aliases
 
- 
getPermissionMessageDeprecated.permission messages have not worked for player-executed commands since 1.13 as clients without permission to execute a command are unaware of its existence and therefore will not send an unknown command execution to the server. This message will only ever be shown to consoles or when this command is executed withBukkit.dispatchCommand(CommandSender, String).Returns a message to be displayed on a failed permission check for this command- Returns:
- Permission check failed message
 
- 
getDescriptionGets a brief description of this command- Returns:
- Description of this command
 
- 
getUsageGets an example usage of this command- Returns:
- One or more example usages
 
- 
setAliasesSets the list of aliases to request on registration for this command. This is not effective outside of defining aliases in thePluginDescriptionFile.getCommands()(under the `aliases' node) is equivalent to this method.- Parameters:
- aliases- aliases to register to this command
- Returns:
- this command object, for chaining
 
- 
setDescriptionSets a brief description of this command. Defining a description in thePluginDescriptionFile.getCommands()(under the `description' node) is equivalent to this method.- Parameters:
- description- new command description
- Returns:
- this command object, for chaining
 
- 
setPermissionMessage@Deprecated(since="1.20.4") @NotNull public Command setPermissionMessage(@Nullable String permissionMessage) Deprecated.permission messages have not worked for player-executed commands since 1.13 as clients without permission to execute a command are unaware of its existence and therefore will not send an unknown command execution to the server. This message will only ever be shown to consoles or when this command is executed withBukkit.dispatchCommand(CommandSender, String).Sets the message sent when a permission check fails- Parameters:
- permissionMessage- new permission message, null to indicate default message, or an empty string to indicate no message
- Returns:
- this command object, for chaining
 
- 
setUsageSets the example usage of this command- Parameters:
- usage- new example usage
- Returns:
- this command object, for chaining
 
- 
broadcastCommandMessage
- 
broadcastCommandMessagepublic static void broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message, boolean sendToSource) 
- 
toString
 
-