wyvern.kernel.commands
Class CommandListImpl

java.lang.Object
  extended bywyvern.kernel.commands.CommandListImpl
All Implemented Interfaces:
CommandList

public class CommandListImpl
extends java.lang.Object
implements CommandList

This object stores Commands. All game commands (built-in or add-on) are Commands. 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
 
Nested classes inherited from class wyvern.lib.CommandList
CommandList.CommandFilter
 
Field Summary
protected  AtmosphereCommands atmospheres_
           
static java.lang.Class[] builtins
          All the built-in game commands must go in this list.
protected  wyvern.kernel.data.MultiHashMap commands_
           
protected  java.util.ArrayList filters_
          The list of objects requesting to get a chance to handle each command as it comes through.
protected  Commandable owner_
          A reference to the Player this list is associated with, if any.
static java.lang.Class[] wiz_builtins
           
 
Constructor Summary
CommandListImpl()
          Creates a CommandListImpl with a set of built-in commands.
CommandListImpl(Commandable c)
          Constructs a new CommandListImpl for the specified Player.
 
Method Summary
protected  void addBuiltIn(java.lang.Class handler)
          Adds a built-in command Singleton to the list.
 void addBuiltInCommands()
          Put the default game commands into the dictionary.
 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.
protected  Command askFilters(java.lang.String cmd)
          Asks the filter objects if they want to handle the command.
protected  boolean commandKnown(Command ex, CommandEvent event)
          Returns true if the command was enqueued by the game engine, OR if it was enqueued by a user and the user is allowed to execute this command.
 void destroy()
          Nukes all the internal structures, for the garbage collector.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

builtins

public static final java.lang.Class[] builtins
All the built-in game commands must go in this list. I suppose we could enumerate a well-defined set of directories looking for BuiltInCommand classes, but this works fine for now.


wiz_builtins

public static final java.lang.Class[] wiz_builtins

commands_

protected transient wyvern.kernel.data.MultiHashMap commands_

atmospheres_

protected transient AtmosphereCommands atmospheres_

filters_

protected transient java.util.ArrayList filters_
The list of objects requesting to get a chance to handle each command as it comes through.


owner_

protected Commandable owner_
A reference to the Player this list is associated with, if any. AIs also create CommandLists for their monster groups, so the Player reference may be null.

Constructor Detail

CommandListImpl

public CommandListImpl()
Creates a CommandListImpl with a set of built-in commands. This constructor is used when the list is being created to drive more than one Commandable, as is the case when a MonsterAI creates a CommandListImpl to share among all its monsters.


CommandListImpl

public CommandListImpl(Commandable c)
Constructs a new CommandListImpl for the specified Player. Some of the built-in game commands may need to know when they're being added who the Player is (if the list is being created for a Player).

Parameters:
c - the Commandable (more flexibility than a Player, just in case we need it) the list is being created for.
Method Detail

reload

public void reload()
Description copied from interface: CommandList
Reloads all the built-in command handlers.

Specified by:
reload in interface CommandList

addBuiltInCommands

public void addBuiltInCommands()
Put the default game commands into the dictionary. Does not include wizard builtin commands. Called by constructor.


addWizBuiltins

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

Specified by:
addWizBuiltins in interface CommandList

addBuiltIn

protected void addBuiltIn(java.lang.Class handler)
Adds a built-in command Singleton to the list.

Parameters:
handler - a built-in command to add to the list

addFilter

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

Specified by:
addFilter in interface CommandList
Parameters:
obj - a filter

removeFilter

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

Specified by:
removeFilter in interface CommandList
Parameters:
obj - the filter to remove

findHandler

public Command findHandler(CommandEvent event)
Description copied from interface: CommandList
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()

Specified by:
findHandler in interface CommandList
Parameters:
event - the CommandEvent containing the command
Returns:
the first Command that claims to recognize this command, or null if the command is unknown.

commandKnown

protected boolean commandKnown(Command ex,
                               CommandEvent event)
Returns true if the command was enqueued by the game engine, OR if it was enqueued by a user and the user is allowed to execute this command. Returns false if the attempted command isn't allowed to be overridden, in which case findHandler() will return null.

Parameters:
ex - the Command handling the command (will implement a special interface if it's off-limits to players).
event - the event encapsulating the command & args

askFilters

protected Command askFilters(java.lang.String cmd)
Asks the filter objects if they want to handle the command. First-come, first-served.

Parameters:
cmd - the command
Returns:
the first command that wants to handle it, if any

registerCommand

public void registerCommand(java.lang.String command,
                            Command handler)
Description copied from interface: CommandList
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.

Specified by:
registerCommand in interface CommandList
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)
Description copied from interface: CommandList
Unregisters a command. The specified handler object will no longer be notified if the user types the command.

Specified by:
unregisterCommand in interface CommandList
Parameters:
command - the command verb to register
handler - the Command object that implements the command

getCommandable

public Commandable getCommandable()
Description copied from interface: CommandList
Returns the Commandable (usually a Player) that this list is associated with. Can return null.

Specified by:
getCommandable in interface CommandList
Returns:
the Commandable using the list, or null if it's being shared.

getCommands

public java.lang.String[] getCommands()
Description copied from interface: CommandList
Returns a list of all the commands in this list.

Specified by:
getCommands in interface CommandList
Returns:
a list of the registered commands.

getCommandMap

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

Specified by:
getCommandMap in interface CommandList

getRegisteredCommands

public Command[] getRegisteredCommands(java.lang.String verb)
Description copied from interface: CommandList
Returns the registered commands for the given Command handler.

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

destroy

public void destroy()
Nukes all the internal structures, for the garbage collector.