public abstract class Command extends Object
Modifier and Type | Field and Description |
---|---|
protected String |
description |
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 current 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.
|
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[] args)
Deprecated.
This method is not supported and returns null
|
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.
|
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 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 ' '@Deprecated public List<String> tabComplete(CommandSender sender, String[] args)
sender
- Source object which is executing this commandargs
- 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 String getName()
public 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)
If the command is currently registered the label change will only take effect after its been re-registered e.g. after a /reload
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 © 2015. All rights reserved.