Package org.bukkit.command

# Class Command

java.lang.Object
org.bukkit.command.Command

Direct Known Subclasses:
  `BukkitCommand`, `FormattedCommandAlias`, `MultipleCommandAlias`, `PluginCommand`

public abstract class Command extends Object
Represents a Command, which executes various tasks upon user input

## Field Summary

Fields
Modifier and Type
Field
Description
`protected String`
`description`
`Timing`
`timings`
`protected String`
`usageMessage`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Command(@NotNull String name)`
`protected`
`Command(@NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List<String> aliases)`

## Method Summary

Modifier and Type
Method
Description
`static void`
`broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message)`
`static void`
`broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message, boolean sendToSource)`
`abstract boolean`
`execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args)`
Executes the command, returning its success
`@NotNull List<String>`
`getAliases()`
Returns a list of active aliases of this command
`@NotNull String`
`getDescription()`
Gets a brief description of this command
`@NotNull String`
`getLabel()`
Returns the label for this command
`@NotNull String`
`getName()`
Returns the name of this command
`@Nullable String`
`getPermission()`
Gets the permission required by users to be able to perform this command
`@Nullable String`
`getPermissionMessage()`
Deprecated.
use `permissionMessage()`
`@NotNull String`
`getTimingName()`
`@NotNull String`
`getUsage()`
Gets an example usage of this command
`boolean`
`isRegistered()`
Returns the current registered state of this command
`Component`
`permissionMessage()`
Gets the permission message.
`void`
`permissionMessage(Component permissionMessage)`
Sets the permission message.
`boolean`
`register(@NotNull CommandMap commandMap)`
Registers this command to a CommandMap.
`@NotNull Command`
`setAliases(@NotNull List<String> aliases)`
Sets the list of aliases to request on registration for this command.
`@NotNull Command`
`setDescription(@NotNull String description)`
Sets a brief description of this command.
`boolean`
`setLabel(@NotNull String name)`
Sets the label of this command.
`boolean`
`setName(@NotNull String name)`
Sets the name of this command.
`void`
`setPermission(@Nullable String permission)`
Sets the permission required by users to be able to perform this command
`@NotNull Command`
`setPermissionMessage(@Nullable String permissionMessage)`
Deprecated.
use `permissionMessage(net.kyori.adventure.text.Component)`
`@NotNull Command`
`setUsage(@NotNull String usage)`
Sets the example usage of this command
`@NotNull List<String>`
`tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args)`
Executed on tab completion for this command, returning a list of options the player can tab through.
`@NotNull List<String>`
`tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args, @Nullable Location location)`
Executed on tab completion for this command, returning a list of options the player can tab through.
`boolean`
`testPermission(@NotNull CommandSender target)`
Tests the given `CommandSender` to see if they can perform this command.
`boolean`
`testPermissionSilent(@NotNull CommandSender target)`
Tests the given `CommandSender` to see if they can perform this command.
`String`
`toString()`
`boolean`
`unregister(@NotNull CommandMap commandMap)`
Unregisters this command from the passed CommandMap applying any outstanding changes

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### description

protected String description

### usageMessage

protected String usageMessage

### timings

public Timing timings

## Constructor Details

### Command

protected Command(@NotNull @NotNull String name)

### Command

protected Command(@NotNull @NotNull String name, @NotNull @NotNull String description, @NotNull @NotNull String usageMessage, @NotNull @NotNull List<String> aliases)

## Method Details

### getTimingName

@NotNull public @NotNull String getTimingName()

### execute

public abstract boolean execute(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String commandLabel, @NotNull @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 @NotNull List<String> tabComplete(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String alias, @NotNull @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 @NotNull List<String> tabComplete(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String alias, @NotNull @NotNull String[] args, @Nullable @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

### getName

@NotNull public @NotNull String getName()
Returns the name of this command

Returns:
  Name of this command

### setName

public boolean setName(@NotNull @NotNull String name)
Sets 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

### getPermission

@Nullable public @Nullable String getPermission()
Gets the permission required by users to be able to perform this command

Returns:
  Permission name, or null if none

### setPermission

public void setPermission(@Nullable @Nullable String permission)
Sets the permission required by users to be able to perform this command

Parameters:
  `permission` - Permission name or null

### testPermission

public boolean testPermission(@NotNull @NotNull CommandSender target)
Tests the given `CommandSender` to 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

### testPermissionSilent

public boolean testPermissionSilent(@NotNull @NotNull CommandSender target)
Tests the given `CommandSender` to 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

### getLabel

@NotNull public @NotNull String getLabel()
Returns the label for this command

Returns:
  Label of this command

### setLabel

public boolean setLabel(@NotNull @NotNull String name)
Sets 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

### register

public boolean register(@NotNull @NotNull CommandMap commandMap)
Registers 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

### unregister

public boolean unregister(@NotNull @NotNull CommandMap commandMap)
Unregisters 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

### isRegistered

public boolean isRegistered()
Returns the current registered state of this command

Returns:
  true if this command is currently registered false otherwise

### getAliases

@NotNull public @NotNull List<String> getAliases()
Returns a list of active aliases of this command

Returns:
  List of aliases

### getPermissionMessage

@Nullable @Deprecated public @Nullable String getPermissionMessage()
Deprecated.
use `permissionMessage()`
Returns a message to be displayed on a failed permission check for this command

Returns:
  Permission check failed message

### getDescription

@NotNull public @NotNull String getDescription()
Gets a brief description of this command

Returns:
  Description of this command

### getUsage

@NotNull public @NotNull String getUsage()
Gets an example usage of this command

Returns:
  One or more example usages

### setAliases

@NotNull public @NotNull Command setAliases(@NotNull @NotNull List<String> aliases)
Sets the list of aliases to request on registration for this command. This is not effective outside of defining aliases in the `PluginDescriptionFile.getCommands()` (under the ``aliases`' node) is equivalent to this method.

Parameters:
  `aliases` - aliases to register to this command
Returns:
  this command object, for chaining

### setDescription

@NotNull public @NotNull Command setDescription(@NotNull @NotNull String description)
Sets a brief description of this command. Defining a description in the `PluginDescriptionFile.getCommands()` (under the ``description`' node) is equivalent to this method.

Parameters:
  `description` - new command description
Returns:
  this command object, for chaining

### setPermissionMessage

@NotNull @Deprecated public @NotNull Command setPermissionMessage(@Nullable @Nullable String permissionMessage)
Deprecated.
use `permissionMessage(net.kyori.adventure.text.Component)`
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

### setUsage

@NotNull public @NotNull Command setUsage(@NotNull @NotNull String usage)
Sets the example usage of this command

Parameters:
  `usage` - new example usage
Returns:
  this command object, for chaining

### permissionMessage

@Nullable public Component permissionMessage()
Gets the permission message.

Returns:
  the permission message

### permissionMessage

public void permissionMessage(@Nullable Component permissionMessage)
Sets the permission message.

Parameters:
  `permissionMessage` - the permission message

### broadcastCommandMessage

public static void broadcastCommandMessage(@NotNull @NotNull CommandSender source, @NotNull @NotNull String message)

### broadcastCommandMessage

public static void broadcastCommandMessage(@NotNull @NotNull CommandSender source, @NotNull @NotNull String message, boolean sendToSource)

### toString

public String toString()

Overrides:
  `toString` in class `Object`