wyvern.kernel.commands
Class SimpleHandler

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.commands.SimpleHandler
All Implemented Interfaces:
BuiltInCommand, Command, PropertyList
Direct Known Subclasses:
AliasCommand, AutobagCommand, AutoGrabCommand, BugCommand, EchoCommand, EmoteCommand, FriendsCommand, InvCommand, JumpSkill, LastCommand, MiscCommands, MonitorCommand, ReadyCommand, ScoreCommand, SkillsCommand, SpellCommand, StartupCommand, TrainCommand, VerboseCommand, Wand.SimpleWandHandler, WarnCommand, WhoCommand

public abstract class SimpleHandler
extends PList
implements BuiltInCommand

This class provides a simple, common-case implementation of the Command interface. Using the SimpleHandler you can handle a game command without worrying about events and event queues. The SimpleHandler will take care of the details.

To use the SimpleHandler class, subclass it and override addCommands() to add any commands you want it to handle. To set a delay for the commands, pass it to the constructor (usually a private/Singleton constructor). Then override handleEvent to perform the command. You can change the delay in handleEvent() if desired. You must return true if the command succeeded and false if it failed.

For commands for which there are parameters to the command that others may want to interact with, the SimpleHandler may not have sufficient flexibility. Use the Command interface to give yourself maximum control over what goes into the event for the command.

Version:
1.0, Jan 29, 1998
Author:
Steve Yegge

Field Summary
protected  int delay_
           
 
Fields inherited from class wyvern.kernel.properties.PList
readOnly_
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Constructor Summary
SimpleHandler()
          Constructs a new SimpleHandler with a command delay of zero.
SimpleHandler(int delay)
          Constructs a new SimpleHandler.
 
Method Summary
abstract  void addCommands(java.util.Map commands, CommandList list)
          Adds our commands.
 CommandEvent createEvent(CommandEvent e)
          Creates a no-parameter event for the specified command.
 boolean execute(CommandEvent event)
          Executes the specified CommandEvent.
abstract  boolean handleEvent(CommandEvent event)
          Callback method for subclasses to handle their command.
 boolean knowsCommand(java.lang.String command)
          By default, we know the command.
 
Methods inherited from class wyvern.kernel.properties.PList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, debugProperties, dismantlePropertyList, getDoubleProperty, getInheritedProperty, getInteger, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProfilingInfo, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, toString, transientlyRemoveProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

delay_

protected int delay_
Constructor Detail

SimpleHandler

public SimpleHandler()
Constructs a new SimpleHandler with a command delay of zero.


SimpleHandler

public SimpleHandler(int delay)
Constructs a new SimpleHandler.

Parameters:
delay - the time (in milliseconds) the command takes for the agent to execute.
Method Detail

addCommands

public abstract void addCommands(java.util.Map commands,
                                 CommandList list)
Adds our commands. Subclasses should override this and, for each command the subclass wants to implement, put it in the "commands" map.

Specified by:
addCommands in interface BuiltInCommand
Parameters:
commands - a Map whose keys are the command verbs, and whose values are references to the SimpleHandler instance that wants to handle the command.
list - the Player, Monster, Vehicle or other CommandList implementation for which addCommands() is being called.

knowsCommand

public boolean knowsCommand(java.lang.String command)
By default, we know the command.

Specified by:
knowsCommand in interface Command
Parameters:
command - the command to check
Returns:
true if we want to handle the command

createEvent

public CommandEvent createEvent(CommandEvent e)
Creates a no-parameter event for the specified command.

Specified by:
createEvent in interface Command
Parameters:
e - a "blank" CommandEvent containing only the command text and the agent who's performing the command. This initial event is created by the originator of the event (e.g. the AI or player's command preprocessor).
Returns:
a CommandEvent subclass encapsulating this command's execution parameters and state. It should copy in the fields from the passed-in event.

execute

public boolean execute(CommandEvent event)
Executes the specified CommandEvent. The CommandEvent contains all the parameters and state required to execute the command; the parameters have been filtered through hook objects, so they may not be the same as when the event was created.

Specified by:
execute in interface Command
Parameters:
event - the CommandEvent to execute
Returns:
true if the event completed successfully, else false.

handleEvent

public abstract boolean handleEvent(CommandEvent event)
Callback method for subclasses to handle their command.

Parameters:
event - a CommandEvent with various fields filled in: the agent performing the command, the command verb and arguments, the delay for the command, and success/failure messages.
Returns:
true if the event was completed successfully; false if it couldn't be executed for some reason. It's important to return the right value, since the appropriate post-hook will be run depending on whether the command succeeded or failed.