Class ShipArivalInPortEventListener
- java.lang.Object
-
- ch.sahits.game.openpatrician.event.handler.ShipArivalInPortEventListener
-
- Direct Known Subclasses:
WaitTimeForShipArrival
public abstract class ShipArivalInPortEventListener extends java.lang.Object
Event listener that implements the event listening for theShipEntersPortEvent
for a specific city and then executesexecute()
. The listener has to be added to the clientServerEventBus by the concrete class.- Author:
- Andi Hotz, (c) Sahits GmbH, 2013 Created on Feb 19, 2013
-
-
Field Summary
Fields Modifier and Type Field Description private ICity
city
protected com.google.common.eventbus.AsyncEventBus
clientServerEventBus
private IPlayer
player
private INavigableVessel
ship
-
Constructor Summary
Constructors Constructor Description ShipArivalInPortEventListener(ICity city, IPlayer player)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
execute()
Execute an action.INavigableVessel
getShip()
The ship that has arrived.void
handleShipEntersPort(ShipEntersPortEvent event)
Handling the event when a ship enters the port.
-
-
-
Field Detail
-
city
private final ICity city
-
player
private final IPlayer player
-
ship
private INavigableVessel ship
-
clientServerEventBus
@Autowired @Qualifier("serverClientEventBus") protected com.google.common.eventbus.AsyncEventBus clientServerEventBus
-
-
Method Detail
-
handleShipEntersPort
public void handleShipEntersPort(ShipEntersPortEvent event)
Handling the event when a ship enters the port. Subclasses are intended to override this implementation by extension implement the correct logic. This base implementation provides two points:- if the player and city that triggered the event match with the ones listed to by this instance the ship is set on this instance
- Then the
execute()
method is called and if it returns true this instance is unregistered from the event bus. Otherwise the ship is set to null.
- Parameters:
event
- for the ship entering the port
-
execute
public abstract boolean execute()
Execute an action.- Returns:
- flag indicating if the execution was successful and therefor the event listener can be removed.
-
getShip
public INavigableVessel getShip()
The ship that has arrived. The ship value is set in thehandleShipEntersPort(ShipEntersPortEvent)
method.- Returns:
- vessel that arrived.
-
-