wyvern.lib
Interface CommandList

All Known Implementing Classes:
CommandListImpl

public interface CommandList

This object stores Commands. All game commands (built-in or add-on) are implemented by Command objects. A Command registers itself with a particular agent (e.g. player or monster) so that the agent can execute the command implemented by the Command. Upon registering, the Command is stored in a table managed by this class.

Version:
1.0, May 15, 1997
Author:
Steve Yegge
See Also:
Command

Nested Class Summary
static interface CommandList.CommandFilter
          This interface is implemented by classes that want a chance to handle *every* command that comes through the queue.
 
Method Summary
 void addFilter(CommandList.CommandFilter obj)
          Adds a filter object (a Command wanting to get the opportunity to handle all commands that come through) to the list.
 void addWizBuiltins()
          Put built-in commands just for Wizards into the dictionary.
 Command findHandler(CommandEvent event)
          Finds an object to handle the specified command.
 Commandable getCommandable()
          Returns the Commandable (usually a Player) that this list is associated with.
 java.util.Map getCommandMap()
          Returns the MultiHashMap mapping commands to handlers.
 java.lang.String[] getCommands()
          Returns a list of all the commands in this list.
 Command[] getRegisteredCommands(java.lang.String verb)
          Returns the registered commands for the given Command handler.
 void registerCommand(java.lang.String command, Command handler)
          Registers a new command command.
 void reload()
          Reloads all the built-in command handlers.
 void removeFilter(CommandList.CommandFilter obj)
          Called by a Command when it wants to get off the list for being requested about handling every command.
 void unregisterCommand(java.lang.String command, Command handler)
          Unregisters a command.
 

Method Detail

addFilter

public void addFilter(CommandList.CommandFilter obj)
Adds a filter object (a Command wanting to get the opportunity to handle all commands that come through) to the list.

Parameters:
obj - a filter

removeFilter

public void removeFilter(CommandList.CommandFilter obj)
Called by a Command when it wants to get off the list for being requested about handling every command.

Parameters:
obj - the filter to remove

findHandler

public Command findHandler(CommandEvent event)
Finds an object to handle the specified command. Looks through the list of Commands registered for this command and chooses the first one that returns true from knowsCommand()

Parameters:
event - the CommandEvent containing the command
Returns:
the first Command that claims to recognize this command, or null if the command is unknown.

registerCommand

public void registerCommand(java.lang.String command,
                            Command handler)
Registers a new command command.

The new command will go at the front of the list of handlers for the command. I.e. the most recently-added command gets first shot at the command.

Parameters:
command - the command verb to register
handler - the Command object that implements the command

unregisterCommand

public void unregisterCommand(java.lang.String command,
                              Command handler)
Unregisters a command. The specified handler object will no longer be notified if the user types the command.

Parameters:
command - the command verb to register
handler - the Command object that implements the command

getCommandable

public Commandable getCommandable()
Returns the Commandable (usually a Player) that this list is associated with. Can return null.

Returns:
the Commandable using the list, or null if it's being shared.

getCommands

public java.lang.String[] getCommands()
Returns a list of all the commands in this list.

Returns:
a list of the registered commands.

getRegisteredCommands

public Command[] getRegisteredCommands(java.lang.String verb)
Returns the registered commands for the given Command handler.

Parameters:
verb - a command verb
Returns:
a list (possibly null or empty) of Commands that claim to know commands starting with the passed verb.

addWizBuiltins

public void addWizBuiltins()
Put built-in commands just for Wizards into the dictionary. Called by constructor if owner has "wizard" property.


getCommandMap

public java.util.Map getCommandMap()
Returns the MultiHashMap mapping commands to handlers. Don't mess with this unless you want to screw the player over.


reload

public void reload()
Reloads all the built-in command handlers.