wyvern.lib.classes.town
Class PostOffice

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.lib.classes.StaticObject
              extended bywyvern.lib.classes.town.PostOffice
All Implemented Interfaces:
Broadcaster, Command, GameObject, MethodHookable, PropertyList

public final class PostOffice
extends StaticObject
implements Command

Handles reading and sending player-based email.

Version:
1.0, Sep 09, 2002
Author:
Steve Yegge

Field Summary
 
Fields inherited from class wyvern.kernel.maps.MapObject
IN_MAP_EDITOR, listenerList_
 
Fields inherited from class wyvern.kernel.properties.PList
readOnly_
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Constructor Summary
PostOffice()
           
 
Method Summary
 CommandEvent createEvent(CommandEvent e)
          Creates a CommandEvent that encapsulates all the state necessary to perform the command.
 boolean delete(CommandEvent e)
          Deletes a message by number.
 boolean execute(CommandEvent event)
          Executes the specified CommandEvent.
static java.util.List getMessages(Player player)
          Returns the player's inbox as a list of wyvern.kernel.mysql.MailMessage objects
static java.util.List getMessages(java.lang.String name)
          Returns the player's inbox as a list of wyvern.kernel.mysql.MailMessage objects
static boolean hasNewMail(Player player)
          Returns true if the specified player has new mail.
 void initialize()
          Initializes the object's default properties.
 boolean knowsCommand(java.lang.String cmd)
          Returns true if this Command wants to handle the command.
 boolean mail(CommandEvent event)
          Sends mail to another player.
 boolean messages(CommandEvent event)
          Shows your messages (read and unread).
 boolean read(CommandEvent event)
          Reads a message, and marks it as read.
 void remove()
          Unregisters commands from the map.
static boolean sendMessage(java.lang.String sender, java.lang.String receiver, java.lang.String body)
          Sends a post-office message to the specified player.
static boolean sendMessage(java.lang.String sender, java.lang.String receiver, java.lang.String subject, java.lang.String body)
          Sends a post-office message to the specified player.
 void setMap(GameMap map, int x, int y)
          Registers commands with the map.
 
Methods inherited from class wyvern.kernel.maps.MapObject
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMethodHook, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, destroy, ensureListenerList, ensureWeight, externalize, fireContainerEntered, fireContainerExited, fireEnteredMap, fireExitedMap, fireMovedInMap, getAlpha, getAppearance, getArchetype, getBaseName, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getValue, getWeight, groupString, inContainer, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCommandable, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMethodHook, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, runMethodHook, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDefaultBitmap, setDefaultCategory, setDefaultDesc, setDefaultImage, setDefaultIntProperty, setDefaultLayer, setDefaultMaterial, setDefaultProperty, setDefaultShortDesc, setDirection, setImage, setImage, setLayer, setLocations, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, teleport, toString, updateMapLocation
 
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, transientlyRemoveProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface wyvern.lib.PropertyList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, getDoubleProperty, getInheritedProperty, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, 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, transientlyRemoveProperty
 

Constructor Detail

PostOffice

public PostOffice()
Method Detail

initialize

public void initialize()
Description copied from interface: GameObject
Initializes the object's default properties. Any GameObject implementation that wishes to initialize itself should do so here, rather than in the constructor. This is because nearly all game objects inherit from an archetype, and the archetype parent pointer isn't set until the object's constructor finishes. This is a good place to add any class-default properties for an object - properties that the object gets regardless of which archetype it inherits from. WARNING: don't forget to call the superclass' initialize() method, or the object may not function properly. For instance, it won't become animated even if it specifies animation parameters in the archetype.

Specified by:
initialize in interface GameObject
Overrides:
initialize in class StaticObject

setMap

public void setMap(GameMap map,
                   int x,
                   int y)
Registers commands with the map.

Specified by:
setMap in interface GameObject
Overrides:
setMap in class MapObject

remove

public void remove()
Unregisters commands from the map.

Specified by:
remove in interface GameObject
Overrides:
remove in class MapObject

knowsCommand

public boolean knowsCommand(java.lang.String cmd)
Description copied from interface: Command
Returns true if this Command wants to handle the command. The Command can examine the arguments and determine that it doesn't actually understand the command, in which case it should return false.

This method exists to allow more than one game object to implement the same command verb, but with different expected arguments.

If two objects register for the same command and the same arguments, the object that was registered most recently gets to handle at the command.

Specified by:
knowsCommand in interface Command
Parameters:
cmd - the entire command string, including arguments
Returns:
true if we want to handle the command

createEvent

public CommandEvent createEvent(CommandEvent e)
Description copied from interface: Command
Creates a CommandEvent that encapsulates all the state necessary to perform the command. A well-designed CommandEvent exposes all of its "properties" so that hook objects can modify its behavior. For instance, many commands result in some sort of message being sent back to the client. The message should be among the properties that hooks can override.

This method is called by the kernel. The kernel passes the event to the pre-hook, then calls Command.execute() (below) to execute the event, and finally calls the post-hook.

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)
Description copied from interface: Command
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.

mail

public boolean mail(CommandEvent event)
Sends mail to another player.


messages

public boolean messages(CommandEvent event)
Shows your messages (read and unread).


read

public boolean read(CommandEvent event)
Reads a message, and marks it as read.


delete

public boolean delete(CommandEvent e)
Deletes a message by number.


hasNewMail

public static boolean hasNewMail(Player player)
Returns true if the specified player has new mail.


getMessages

public static java.util.List getMessages(Player player)
Returns the player's inbox as a list of wyvern.kernel.mysql.MailMessage objects

Parameters:
player - the player
Returns:
a possibly empty List of their messages

getMessages

public static java.util.List getMessages(java.lang.String name)
Returns the player's inbox as a list of wyvern.kernel.mysql.MailMessage objects

Parameters:
name - the name of the player
Returns:
a possibly empty List of their messages

sendMessage

public static boolean sendMessage(java.lang.String sender,
                                  java.lang.String receiver,
                                  java.lang.String body)
                           throws java.lang.Exception
Sends a post-office message to the specified player.

Parameters:
sender - whoever the mail is from
receiver - the player to receive mail. Throws an IllegalArgumentException if the player doesn't exist.
body - the body of the message
Returns:
true if it succeeded, false if some error occurred
Throws:
java.lang.IllegalArgumentException - or NullPointerException if one of the args was invalid
java.lang.Exception

sendMessage

public static boolean sendMessage(java.lang.String sender,
                                  java.lang.String receiver,
                                  java.lang.String subject,
                                  java.lang.String body)
                           throws java.lang.Exception
Sends a post-office message to the specified player.

Parameters:
receiver - the player to receive mail. Throws an IllegalArgumentException if the player doesn't exist.
sender - whoever the mail is from (cannot be null)
subject - optional subject of the message (255 chars max, can be null)
body - the body of the message (cannot be null)
Returns:
true if it succeeded, false if some error occurred
Throws:
java.lang.IllegalArgumentException - or NullPointerException if one of the args was invalid
java.lang.Exception