Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.command.Command Class Referenceabstract
Inheritance diagram for org.bukkit.command.Command:
org.bukkit.command.defaults.BukkitCommand org.bukkit.command.defaults.VanillaCommand org.bukkit.command.FormattedCommandAlias org.bukkit.command.MultipleCommandAlias org.bukkit.command.PluginCommand org.bukkit.command.defaults.PluginsCommand org.bukkit.command.defaults.ReloadCommand org.bukkit.command.defaults.TimingsCommand org.bukkit.command.defaults.VersionCommand org.bukkit.command.defaults.AchievementCommand org.bukkit.command.defaults.BanCommand org.bukkit.command.defaults.BanIpCommand org.bukkit.command.defaults.BanListCommand org.bukkit.command.defaults.ClearCommand org.bukkit.command.defaults.DefaultGameModeCommand org.bukkit.command.defaults.DeopCommand org.bukkit.command.defaults.DifficultyCommand org.bukkit.command.defaults.EffectCommand org.bukkit.command.defaults.EnchantCommand org.bukkit.command.defaults.ExpCommand org.bukkit.command.defaults.GameModeCommand org.bukkit.command.defaults.GameRuleCommand org.bukkit.command.defaults.GiveCommand org.bukkit.command.defaults.HelpCommand org.bukkit.command.defaults.KickCommand org.bukkit.command.defaults.KillCommand org.bukkit.command.defaults.ListCommand org.bukkit.command.defaults.MeCommand org.bukkit.command.defaults.OpCommand org.bukkit.command.defaults.PardonCommand org.bukkit.command.defaults.PardonIpCommand org.bukkit.command.defaults.PlaySoundCommand org.bukkit.command.defaults.SaveCommand org.bukkit.command.defaults.SaveOffCommand org.bukkit.command.defaults.SaveOnCommand org.bukkit.command.defaults.SayCommand org.bukkit.command.defaults.ScoreboardCommand org.bukkit.command.defaults.SeedCommand org.bukkit.command.defaults.SetIdleTimeoutCommand org.bukkit.command.defaults.SetWorldSpawnCommand org.bukkit.command.defaults.SpawnpointCommand org.bukkit.command.defaults.SpreadPlayersCommand org.bukkit.command.defaults.StopCommand org.bukkit.command.defaults.TeleportCommand org.bukkit.command.defaults.TellCommand org.bukkit.command.defaults.TestForCommand org.bukkit.command.defaults.TimeCommand org.bukkit.command.defaults.ToggleDownfallCommand org.bukkit.command.defaults.WeatherCommand org.bukkit.command.defaults.WhitelistCommand

Public Member Functions

abstract boolean execute (CommandSender sender, String commandLabel, String[] args)
List< String > tabComplete (CommandSender sender, String[] args)
List< String > tabComplete (CommandSender sender, String alias, String[] args) throws IllegalArgumentException
String getName ()
String getPermission ()
void setPermission (String permission)
boolean testPermission (CommandSender target)
boolean testPermissionSilent (CommandSender target)
String getLabel ()
boolean setLabel (String name)
boolean register (CommandMap commandMap)
boolean unregister (CommandMap commandMap)
boolean isRegistered ()
List< String > getAliases ()
String getPermissionMessage ()
String getDescription ()
String getUsage ()
Command setAliases (List< String > aliases)
Command setDescription (String description)
Command setPermissionMessage (String permissionMessage)
Command setUsage (String usage)
String toString ()

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

String description = ""
String usageMessage

Detailed Description

Represents a Command, which executes various tasks upon user input

Definition at line 23 of file command/Command.java.

Member Function Documentation

abstract boolean org.bukkit.command.Command.execute ( CommandSender  sender,
String  commandLabel,
String[]  args 

Executes the command, returning its success

senderSource object which is executing this command
commandLabelThe alias of the command used
argsAll arguments passed to the command, split via ' '
true if the command was successful, otherwise false

Referenced by org.bukkit.command.SimpleCommandMap.dispatch().

List<String> org.bukkit.command.Command.getAliases ( )

Returns a list of active aliases of this command

List of aliases

Definition at line 264 of file command/Command.java.

264  {
265  return activeAliases;
266  }
String org.bukkit.command.Command.getDescription ( )

Gets a brief description of this command

Description of this command

Definition at line 283 of file command/Command.java.

283  {
284  return description;
285  }
String org.bukkit.command.Command.getLabel ( )

Returns the current label for this command

Label of this command or null if not registered

Definition at line 186 of file command/Command.java.

186  {
187  return label;
188  }
String org.bukkit.command.Command.getName ( )

Returns the name of this command

Name of this command

Definition at line 108 of file command/Command.java.

108  {
109  return name;
110  }
String org.bukkit.command.Command.getPermission ( )

Gets the permission required by users to be able to perform this command

Permission name, or null if none

Definition at line 118 of file command/Command.java.

118  {
119  return permission;
120  }
String org.bukkit.command.Command.getPermissionMessage ( )

Returns a message to be displayed on a failed permission check for this command

Permission check failed message

Definition at line 274 of file command/Command.java.

274  {
275  return permissionMessage;
276  }
String org.bukkit.command.Command.getUsage ( )

Gets an example usage of this command

One or more example usages

Definition at line 292 of file command/Command.java.

292  {
293  return usageMessage;
294  }
boolean org.bukkit.command.Command.isRegistered ( )

Returns the current registered state of this command

true if this command is currently registered false otherwise

Definition at line 255 of file command/Command.java.

Referenced by org.bukkit.command.Command.setAliases(), and org.bukkit.command.Command.setLabel().

255  {
256  return (null != this.commandMap);
257  }
boolean org.bukkit.command.Command.register ( CommandMap  commandMap)

Registers this command to a CommandMap. Once called it only allows changes the registered CommandMap

commandMapthe CommandMap to register this command to
true if the registration was successful (the current registered CommandMap was the passed CommandMap or null) false otherwise

Definition at line 217 of file command/Command.java.

217  {
218  if (allowChangesFrom(commandMap)) {
219  this.commandMap = commandMap;
220  return true;
221  }
223  return false;
224  }
Command org.bukkit.command.Command.setAliases ( 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.

aliasesaliases to register to this command
this command object, for chaining

Definition at line 305 of file command/Command.java.

References org.bukkit.command.Command.isRegistered().

305  {
306  this.aliases = aliases;
307  if (!isRegistered()) {
308  this.activeAliases = new ArrayList<String>(aliases);
309  }
310  return this;
311  }
Command org.bukkit.command.Command.setDescription ( 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.

descriptionnew command description
this command object, for chaining

Definition at line 321 of file command/Command.java.

321  {
322  this.description = description;
323  return this;
324  }
boolean org.bukkit.command.Command.setLabel ( String  name)

Sets the label of this command.

If the command is currently registered the label change will only take effect after its been re-registered e.g. after a /reload

nameThe command's name
returns true if the name change happened instantly or false if it was scheduled for re-registration

Definition at line 200 of file command/Command.java.

References org.bukkit.command.Command.isRegistered().

200  {
201  this.nextLabel = name;
202  if (!isRegistered()) {
203  this.label = name;
204  return true;
205  }
206  return false;
207  }
void org.bukkit.command.Command.setPermission ( String  permission)

Sets the permission required by users to be able to perform this command

permissionPermission name or null

Definition at line 128 of file command/Command.java.

128  {
129  this.permission = permission;
130  }
Command org.bukkit.command.Command.setPermissionMessage ( String  permissionMessage)

Sets the message sent when a permission check fails

permissionMessagenew permission message, null to indicate default message, or an empty string to indicate no message
this command object, for chaining

Definition at line 333 of file command/Command.java.

333  {
334  this.permissionMessage = permissionMessage;
335  return this;
336  }
Command org.bukkit.command.Command.setUsage ( String  usage)

Sets the example usage of this command

usagenew example usage
this command object, for chaining

Definition at line 344 of file command/Command.java.

344  {
345  this.usageMessage = usage;
346  return this;
347  }
List<String> org.bukkit.command.Command.tabComplete ( CommandSender  sender,
String[]  args 
This method is not supported and returns null

Definition at line 63 of file command/Command.java.

Referenced by org.bukkit.command.SimpleCommandMap.tabComplete().

63  {
64  return null;
65  }
List<String> org.bukkit.command.Command.tabComplete ( CommandSender  sender,
String  alias,
String[]  args 
) throws IllegalArgumentException

Executed on tab completion for this command, returning a list of options the player can tab through.

senderSource object which is executing this command
aliasthe alias being used
argsAll arguments passed to the command, split via ' '
a list of tab-completions for the specified arguments. This will never be null. List may be immutable.
IllegalArgumentExceptionif sender, alias, or args is null

Definition at line 78 of file command/Command.java.

References org.bukkit.entity.Player.canSee(), org.bukkit.command.CommandSender.getName(), org.bukkit.Server.getOnlinePlayers(), org.bukkit.command.CommandSender.getServer(), and org.bukkit.util.StringUtil.startsWithIgnoreCase().

78  {
79  Validate.notNull(sender, "Sender cannot be null");
80  Validate.notNull(args, "Arguments cannot be null");
81  Validate.notNull(alias, "Alias cannot be null");
83  if (args.length == 0) {
84  return ImmutableList.of();
85  }
87  String lastWord = args[args.length - 1];
89  Player senderPlayer = sender instanceof Player ? (Player) sender : null;
91  ArrayList<String> matchedPlayers = new ArrayList<String>();
92  for (Player player : sender.getServer().getOnlinePlayers()) {
93  String name = player.getName();
94  if ((senderPlayer == null || senderPlayer.canSee(player)) && StringUtil.startsWithIgnoreCase(name, lastWord)) {
95  matchedPlayers.add(name);
96  }
97  }
99  Collections.sort(matchedPlayers, String.CASE_INSENSITIVE_ORDER);
100  return matchedPlayers;
101  }
boolean org.bukkit.command.Command.testPermission ( 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.

targetUser to test
true if they can use it, otherwise false

Definition at line 142 of file command/Command.java.

References org.bukkit.ChatColor.RED, org.bukkit.command.CommandSender.sendMessage(), and org.bukkit.command.Command.testPermissionSilent().

Referenced by org.bukkit.command.PluginCommand.execute().

142  {
143  if (testPermissionSilent(target)) {
144  return true;
145  }
147  if (permissionMessage == null) {
148  target.sendMessage(ChatColor.RED + "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error.");
149  } else if (permissionMessage.length() != 0) {
150  for (String line : permissionMessage.replace("<permission>", permission).split("\n")) {
151  target.sendMessage(line);
152  }
153  }
155  return false;
156  }
boolean testPermissionSilent(CommandSender target)
boolean org.bukkit.command.Command.testPermissionSilent ( CommandSender  target)

Tests the given CommandSender to see if they can perform this command.

No error is sent to the sender.

targetUser to test
true if they can use it, otherwise false

Definition at line 167 of file command/Command.java.

References org.bukkit.permissions.Permissible.hasPermission().

Referenced by org.bukkit.command.SimpleCommandMap.tabComplete(), and org.bukkit.command.Command.testPermission().

167  {
168  if ((permission == null) || (permission.length() == 0)) {
169  return true;
170  }
172  for (String p : permission.split(";")) {
173  if (target.hasPermission(p)) {
174  return true;
175  }
176  }
178  return false;
179  }
boolean org.bukkit.command.Command.unregister ( CommandMap  commandMap)

Unregisters this command from the passed CommandMap applying any outstanding changes

commandMapthe CommandMap to unregister
true if the unregistration was successfull (the current registered CommandMap was the passed CommandMap or null) false otherwise

Definition at line 235 of file command/Command.java.

235  {
236  if (allowChangesFrom(commandMap)) {
237  this.commandMap = null;
238  this.activeAliases = new ArrayList<String>(this.aliases);
239  this.label = this.nextLabel;
240  return true;
241  }
243  return false;
244  }

The documentation for this class was generated from the following file: