com.quartercode.quarterbukkit.api.command
Class CommandExecutor

java.lang.Object
  extended by com.quartercode.quarterbukkit.api.command.CommandExecutor
All Implemented Interfaces:
org.bukkit.command.CommandExecutor

public class CommandExecutor
extends java.lang.Object
implements org.bukkit.command.CommandExecutor

This class is a CommandExecutor for easy creating commands like /command help 1 without using millions of ifs. It's easy to use and created for a fast developement progress.


Constructor Summary
CommandExecutor(org.bukkit.plugin.Plugin plugin)
          Creates a new CommandExecutor which can be used as Bukkit-CommandExecutor.
CommandExecutor(org.bukkit.plugin.Plugin plugin, java.lang.String... commands)
          Creates a new CommandExecutor which can be used as Bukkit-CommandExecutor.
 
Method Summary
 void addCommandHandler(CommandHandler commandHandler)
          Registers a CommandHandler.
 boolean containsCommandHandler(CommandHandler commandHandler)
          Returns if a CommandHandler is registered.
 boolean containsCommandHandler(java.lang.String label)
          Returns if a CommandHandler with a defined label is registered.
 boolean equals(java.lang.Object obj)
           
 CommandHandler getCommandHandler(java.lang.String label)
          Returns the CommandHandler which contains a defined label.
 java.util.List<CommandHandler> getCommandHandlers()
          Returns all registered command handlers as an unmodifiable list.
 int hashCode()
           
 boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, java.lang.String label, java.lang.String[] arguments)
          The main method called by the Bukkit-Command-System.
 void removeCommandHandler(CommandHandler commandHandler)
          Unregisters a CommandHandler.
 void removeCommandHandler(java.lang.String label)
          Unregisters a CommandHandler which has this label.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CommandExecutor

public CommandExecutor(org.bukkit.plugin.Plugin plugin)
Creates a new CommandExecutor which can be used as Bukkit-CommandExecutor. You can bind the executor to a command by using Bukkit.getPluginCommand(command).setExecutor(commandExecutor).

Parameters:
plugin - The plugin for the CommandExecutor.

CommandExecutor

public CommandExecutor(org.bukkit.plugin.Plugin plugin,
                       java.lang.String... commands)
Creates a new CommandExecutor which can be used as Bukkit-CommandExecutor. It binds the defined commands automatically to this executor.

Parameters:
plugin - The plugin for the CommandExecutor.
commands - The commands this executor bind to.
Method Detail

onCommand

public boolean onCommand(org.bukkit.command.CommandSender sender,
                         org.bukkit.command.Command command,
                         java.lang.String label,
                         java.lang.String[] arguments)
The main method called by the Bukkit-Command-System. This is only for the Bukkit-System, don't call it manually!

Specified by:
onCommand in interface org.bukkit.command.CommandExecutor
Parameters:
sender - The CommandSender who executed the command.
command - The Bukkit-Command.
label - The first command label.
arguments - The unparsed (raw) arguments behind the first label (seperated with spaces).
Returns:
If the command was executed (here always true).

getCommandHandlers

public java.util.List<CommandHandler> getCommandHandlers()
Returns all registered command handlers as an unmodifiable list.

Returns:
The registered command handlers.

getCommandHandler

public CommandHandler getCommandHandler(java.lang.String label)
Returns the CommandHandler which contains a defined label. Throws an IllegalStateException if no CommandHandler with the label is registered.

Parameters:
label - The command label.
Returns:
The CommandHandler.

containsCommandHandler

public boolean containsCommandHandler(CommandHandler commandHandler)
Returns if a CommandHandler is registered. Use this for checking before other CommandHandler-functions in this class, like get, register, unregister.

Parameters:
commandHandler - The CommandHandler to check.
Returns:
If the CommandHandler is registered.

containsCommandHandler

public boolean containsCommandHandler(java.lang.String label)
Returns if a CommandHandler with a defined label is registered. Use this for checking before other CommandHandler-functions in this class, like get, register, unregister.

Parameters:
label - The label to check.
Returns:
If a CommandHandler with the label is registered.

addCommandHandler

public void addCommandHandler(CommandHandler commandHandler)
Registers a CommandHandler. Throws an IllegalStateException if the CommandHandler is already registered or there's already a CommandHandler with a label of the one to register.

Parameters:
commandHandler - The CommandHandler to register.

removeCommandHandler

public void removeCommandHandler(CommandHandler commandHandler)
Unregisters a CommandHandler. Throws an IllegalStateException if the CommandHandler isn't registered.

Parameters:
commandHandler - The CommandHandler to unregister.

removeCommandHandler

public void removeCommandHandler(java.lang.String label)
Unregisters a CommandHandler which has this label. Throws an IllegalStateException if no CommandHandler with the label is registered.

Parameters:
label - The CommandHandler with this label to unregister.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object