-
-
Notifications
You must be signed in to change notification settings - Fork 0
Timers
Agony Forge has several built in timers that you can listen to in order to perform timed events such as fights, NPC AI, or spells wearing off. The timers are implemented in such a way that they are safe to use even when you have multiple servers running together in a cluster. The servers work together to determine which one will process each timer event so that we don't accidentally process them more than once.
There are built in timers on the following schedules that you can listen for:
- Once per day
- Once per hour
- Once per minute
- Once per second
To use the built in timers you will need to implement a Spring bean that has a @EventListner
annotated method on it. It will accept a TimerEvent
as an argument. Upon receiving the event, you can check its frequency to see if it is the one you are waiting for. If it is, you can perform the actions that your timer needs. Here's a simple code example:
@EventListener
public void onTimerEvent(TimerEvent event) {
if (!TimeUnit.MINUTES.equals(event.getFrequency())) {
return;
}
LOGGER.info("It has been one minute!");
}