public abstract class Command extends Object
Modifier and Type | Field and Description |
---|---|
protected String |
description |
CustomTimingsHandler |
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 |
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 CustomTimingsHandler timings
protected Command(String name)
public abstract boolean execute(CommandSender sender, String commandLabel, String[] args)
sender
- Source object which is executing this commandcommandLabel
- The alias of the command usedargs
- All arguments passed to the command, split via ' 'public List<String> tabComplete(CommandSender sender, String alias, 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 nullpublic List<String> tabComplete(CommandSender sender, String alias, String[] args, 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 nullpublic String getName()
public boolean setName(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 namepublic String getPermission()
public void setPermission(String permission)
permission
- Permission name or nullpublic boolean testPermission(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(CommandSender target)
CommandSender
to see if they can perform this
command.
No error is sent to the sender.
target
- User to testpublic String getLabel()
public boolean setLabel(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(CommandMap commandMap)
commandMap
- the CommandMap to register this command topublic boolean unregister(CommandMap commandMap)
commandMap
- the CommandMap to unregisterpublic boolean isRegistered()
public List<String> getAliases()
public String getPermissionMessage()
public String getDescription()
public String getUsage()
public Command setAliases(List<String> aliases)
PluginDescriptionFile.getCommands()
(under the
`aliases
' node) is equivalent to this method.aliases
- aliases to register to this commandpublic Command setDescription(String description)
PluginDescriptionFile.getCommands()
(under the
`description
' node) is equivalent to this method.description
- new command descriptionpublic Command setPermissionMessage(String permissionMessage)
permissionMessage
- new permission message, null to indicate
default message, or an empty string to indicate no messagepublic Command setUsage(String usage)
usage
- new example usagepublic static void broadcastCommandMessage(CommandSender source, String message)
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource)
Copyright © 2016. All rights reserved.