Class OnePlayerArea

All Implemented Interfaces:
MovementListener, Killer, Cloneable, Iterable<String>, Serializable

public class OnePlayerArea extends AreaEntity implements MovementListener
An area that only allows one play at a time to enter.
  • Field Details

    • occupantRef

      protected WeakReference<Player> occupantRef
      The reference to the entity currently in the area.
  • Constructor Details

    • OnePlayerArea

      public OnePlayerArea(int width, int height)
      Create a one player area.
      Parameters:
      width - The area width.
      height - The area height.
  • Method Details

    • clearOccupant

      protected void clearOccupant()
      Clear the occupant.
    • contains

      protected boolean contains(Entity entity)
      Check if an entity is in this area.
      Parameters:
      entity - The entity to check.
      Returns:
      true if the entity is in this area.
    • getOccupant

      protected Player getOccupant()
      Get the occupant.
      Returns:
      The area occupant, or null in none.
    • setOccupant

      protected void setOccupant(Player player)
      Set the occupant.
      Parameters:
      player - The occupant to set.
    • isObstacle

      public boolean isObstacle(Entity entity)
      Checks whether players, NPC's, etc. can walk over this entity.
      Overrides:
      isObstacle in class Entity
      Parameters:
      entity - The entity trying to enter.
      Returns:
      true if a Player is given and it is occupied by someone else.
    • onAdded

      public void onAdded(StendhalRPZone zone)
      Called when this object is added to a zone.
      Overrides:
      onAdded in class AreaEntity
      Parameters:
      zone - The zone this was added to.
    • onRemoved

      public void onRemoved(StendhalRPZone zone)
      Called when this object is being removed from a zone.
      Overrides:
      onRemoved in class AreaEntity
      Parameters:
      zone - The zone this will be removed from.
    • update

      public void update()
      Handle object attribute change(s).
      Overrides:
      update in class Entity
    • onEntered

      public void onEntered(ActiveEntity entity, StendhalRPZone zone, int newX, int newY)
      Invoked when an entity enters the object area.
      Specified by:
      onEntered in interface MovementListener
      Parameters:
      entity - The entity that moved.
      zone - The new zone.
      newX - The new X coordinate.
      newY - The new Y coordinate.
    • onExited

      public void onExited(ActiveEntity entity, StendhalRPZone zone, int oldX, int oldY)
      Invoked when an entity leaves the object area.
      Specified by:
      onExited in interface MovementListener
      Parameters:
      entity - The entity that entered.
      zone - The old zone.
      oldX - The old X coordinate.
      oldY - The old Y coordinate.
    • onMoved

      public void onMoved(ActiveEntity entity, StendhalRPZone zone, int oldX, int oldY, int newX, int newY)
      Invoked when an entity moves while over the object area.
      Specified by:
      onMoved in interface MovementListener
      Parameters:
      entity - The entity that left.
      zone - The zone.
      oldX - The old X coordinate.
      oldY - The old Y coordinate.
      newX - The new X coordinate.
      newY - The new Y coordinate.
    • beforeMove

      public void beforeMove(ActiveEntity entity, StendhalRPZone zone, int oldX, int oldY, int newX, int newY)
      Description copied from interface: MovementListener
      Invoked before an entity moves while over the object area.
      Specified by:
      beforeMove in interface MovementListener
      Parameters:
      entity - The entity that left.
      zone - The zone.
      oldX - The old X coordinate.
      oldY - The old Y coordinate.
      newX - The new X coordinate.
      newY - The new Y coordinate.