Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.command.PluginCommand Class Reference
Inheritance diagram for org.bukkit.command.PluginCommand:
org.bukkit.command.Command org.bukkit.command.PluginIdentifiableCommand

Public Member Functions

boolean execute (CommandSender sender, String commandLabel, String[] args)
 
void setExecutor (CommandExecutor executor)
 
CommandExecutor getExecutor ()
 
void setTabCompleter (TabCompleter completer)
 
TabCompleter getTabCompleter ()
 
Plugin getPlugin ()
 
java.util.List< String > tabComplete (CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException
 
String toString ()
 
- Public Member Functions inherited from org.bukkit.command.Command
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 ()
 

Protected Member Functions

 PluginCommand (String name, Plugin owner)
 
- Protected Member Functions inherited from org.bukkit.command.Command
 Command (String name)
 
 Command (String name, String description, String usageMessage, List< String > aliases)
 

Additional Inherited Members

- Static Public Member Functions inherited from org.bukkit.command.Command
static void broadcastCommandMessage (CommandSender source, String message)
 
static void broadcastCommandMessage (CommandSender source, String message, boolean sendToSource)
 
- Protected Attributes inherited from org.bukkit.command.Command
String description = ""
 
String usageMessage
 

Detailed Description

Represents a Command belonging to a plugin

Definition at line 11 of file PluginCommand.java.

Member Function Documentation

boolean org.bukkit.command.PluginCommand.execute ( CommandSender  sender,
String  commandLabel,
String[]  args 
)

Executes the command, returning its success

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

Definition at line 32 of file PluginCommand.java.

References org.bukkit.plugin.Plugin.getDescription(), org.bukkit.plugin.PluginDescriptionFile.getFullName(), org.bukkit.plugin.Plugin.isEnabled(), org.bukkit.command.CommandExecutor.onCommand(), org.bukkit.command.CommandSender.sendMessage(), and org.bukkit.command.Command.testPermission().

32  {
33  boolean success = false;
34 
35  if (!owningPlugin.isEnabled()) {
36  return false;
37  }
38 
39  if (!testPermission(sender)) {
40  return true;
41  }
42 
43  try {
44  success = executor.onCommand(sender, this, commandLabel, args);
45  } catch (Throwable ex) {
46  throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + owningPlugin.getDescription().getFullName(), ex);
47  }
48 
49  if (!success && usageMessage.length() > 0) {
50  for (String line : usageMessage.replace("<command>", commandLabel).split("\n")) {
51  sender.sendMessage(line);
52  }
53  }
54 
55  return success;
56  }
boolean testPermission(CommandSender target)
boolean onCommand(CommandSender sender, Command command, String label, String[] args)
PluginDescriptionFile getDescription()
CommandExecutor org.bukkit.command.PluginCommand.getExecutor ( )

Gets the CommandExecutor associated with this command

Returns
CommandExecutor object linked to this command

Definition at line 72 of file PluginCommand.java.

72  {
73  return executor;
74  }
Plugin org.bukkit.command.PluginCommand.getPlugin ( )

Gets the owner of this PluginCommand

Returns
Plugin that owns this command

Implements org.bukkit.command.PluginIdentifiableCommand.

Definition at line 102 of file PluginCommand.java.

Referenced by org.bukkit.plugin.java.JavaPlugin.getCommand().

102  {
103  return owningPlugin;
104  }
TabCompleter org.bukkit.command.PluginCommand.getTabCompleter ( )

Gets the TabCompleter associated with this command.

Returns
TabCompleter object linked to this command

Definition at line 93 of file PluginCommand.java.

93  {
94  return completer;
95  }
void org.bukkit.command.PluginCommand.setExecutor ( CommandExecutor  executor)

Sets the CommandExecutor to run when parsing this command

Parameters
executorNew executor to run

Definition at line 63 of file PluginCommand.java.

63  {
64  this.executor = executor == null ? owningPlugin : executor;
65  }
void org.bukkit.command.PluginCommand.setTabCompleter ( TabCompleter  completer)

Sets the TabCompleter to run when tab-completing this command.

If no TabCompleter is specified, and the command's executor implements TabCompleter, then the executor will be used for tab completion.

Parameters
completerNew tab completer

Definition at line 84 of file PluginCommand.java.

84  {
85  this.completer = completer;
86  }
java.util.List<String> org.bukkit.command.PluginCommand.tabComplete ( CommandSender  sender,
String  alias,
String[]  args 
) throws CommandException, IllegalArgumentException

Delegates to the tab completer if present.

If it is not present or returns null, will delegate to the current command executor if it implements TabCompleter. If a non-null list has not been found, will default to standard player name completion in Command#tabComplete(CommandSender, String, String[]).

This method does not consider permissions.

Exceptions
CommandExceptionif the completer or executor throw an exception during the process of tab-completing.
IllegalArgumentExceptionif sender, alias, or args is null

Definition at line 124 of file PluginCommand.java.

References org.bukkit.plugin.Plugin.getDescription(), org.bukkit.plugin.PluginDescriptionFile.getFullName(), and org.bukkit.command.TabCompleter.onTabComplete().

124  {
125  Validate.notNull(sender, "Sender cannot be null");
126  Validate.notNull(args, "Arguments cannot be null");
127  Validate.notNull(alias, "Alias cannot be null");
128 
129  List<String> completions = null;
130  try {
131  if (completer != null) {
132  completions = completer.onTabComplete(sender, this, alias, args);
133  }
134  if (completions == null && executor instanceof TabCompleter) {
135  completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
136  }
137  } catch (Throwable ex) {
138  StringBuilder message = new StringBuilder();
139  message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
140  for (String arg : args) {
141  message.append(arg).append(' ');
142  }
143  message.deleteCharAt(message.length() - 1).append("' in plugin ").append(owningPlugin.getDescription().getFullName());
144  throw new CommandException(message.toString(), ex);
145  }
146 
147  if (completions == null) {
148  return super.tabComplete(sender, alias, args);
149  }
150  return completions;
151  }
List< String > onTabComplete(CommandSender sender, Command command, String alias, String[] args)
PluginDescriptionFile getDescription()

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