public abstract class Command extends Object
Modifier and Type | Field and Description |
---|---|
protected String |
description |
Timing |
timings |
protected String |
usageMessage |
Modifier | Constructor and Description |
---|---|
protected |
Command(String name) |
protected |
Command(String name,
String description,
String usageMessage,
List<String> aliases) |
Modifier and Type | Method and Description |
---|---|
static void |
broadcastCommandMessage(CommandSender source,
String message) |
static void |
broadcastCommandMessage(CommandSender source,
String message,
boolean sendToSource) |
abstract boolean |
execute(CommandSender sender,
String commandLabel,
String[] args)
Executes the command, returning its success
|
List<String> |
getAliases()
Returns a list of active aliases of this command
|
String |
getDescription()
Gets a brief description of this command
|
String |
getLabel()
Returns the label for this command
|
String |
getName()
Returns the name of this command
|
String |
getPermission()
Gets the permission required by users to be able to perform this
command
|
String |
getPermissionMessage()
Returns a message to be displayed on a failed permission check for this
command
|
String |
getTimingName() |
String |
getUsage()
Gets an example usage of this command
|
boolean |
isRegistered()
Returns the current registered state of this command
|
boolean |
register(CommandMap commandMap)
Registers this command to a CommandMap.
|
Command |
setAliases(List<String> aliases)
Sets the list of aliases to request on registration for this command.
|
Command |
setDescription(String description)
Sets a brief description of this command.
|
boolean |
setLabel(String name)
Sets the label of this command.
|
boolean |
setName(String name)
Sets the name of this command.
|
void |
setPermission(String permission)
Sets the permission required by users to be able to perform this
command
|
Command |
setPermissionMessage(String permissionMessage)
Sets the message sent when a permission check fails
|
Command |
setUsage(String usage)
Sets the example usage of this command
|
List<String> |
tabComplete(CommandSender sender,
String alias,
String[] args)
Executed on tab completion for this command, returning a list of
options the player can tab through.
|
List<String> |
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.
|
boolean |
testPermission(CommandSender target)
Tests the given
CommandSender to see if they can perform this
command. |
boolean |
testPermissionSilent(CommandSender target)
Tests the given
CommandSender to see if they can perform this
command. |
String |
toString() |
boolean |
unregister(CommandMap commandMap)
Unregisters this command from the passed CommandMap applying any
outstanding changes
|
protected String description
protected String usageMessage
public Timing timings
protected Command(@NotNull String name)
@NotNull public String getTimingName()
public abstract boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args)
sender
- Source object which is executing this commandcommandLabel
- The alias of the command usedargs
- All arguments passed to the command, split via ' '@NotNull public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
sender
- Source object which is executing this commandalias
- the alias being usedargs
- All arguments passed to the command, split via ' 'IllegalArgumentException
- if sender, alias, or args is null@NotNull public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args, @Nullable Location location) throws IllegalArgumentException
sender
- Source object which is executing this commandalias
- the alias being usedargs
- All arguments passed to the command, split via ' 'location
- The position looked at by the sender, or null if noneIllegalArgumentException
- if sender, alias, or args is null@NotNull public String getName()
public boolean setName(@NotNull String name)
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.
name
- New command name@Nullable public String getPermission()
public void setPermission(@Nullable String permission)
permission
- Permission name or nullpublic boolean testPermission(@NotNull CommandSender target)
CommandSender
to see if they can perform this
command.
If they do not have permission, they will be informed that they cannot do this.
target
- User to testpublic boolean testPermissionSilent(@NotNull CommandSender target)
CommandSender
to see if they can perform this
command.
No error is sent to the sender.
target
- User to test@NotNull public String getLabel()
public boolean setLabel(@NotNull String name)
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.
name
- The command's namepublic boolean register(@NotNull CommandMap commandMap)
commandMap
- the CommandMap to register this command topublic boolean unregister(@NotNull CommandMap commandMap)
commandMap
- the CommandMap to unregisterpublic boolean isRegistered()
@NotNull public List<String> getAliases()
@Nullable public String getPermissionMessage()
@NotNull public String getDescription()
@NotNull public String getUsage()
@NotNull public Command setAliases(@NotNull List<String> aliases)
PluginDescriptionFile.getCommands()
(under the
`aliases
' node) is equivalent to this method.aliases
- aliases to register to this command@NotNull public Command setDescription(@NotNull String description)
PluginDescriptionFile.getCommands()
(under the
`description
' node) is equivalent to this method.description
- new command description@NotNull public Command setPermissionMessage(@Nullable String permissionMessage)
permissionMessage
- new permission message, null to indicate
default message, or an empty string to indicate no message@NotNull public Command setUsage(@NotNull String usage)
usage
- new example usagepublic static void broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message)
public static void broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message, boolean sendToSource)
Copyright © 2022. All rights reserved.