Countdown tasks
A countdown task is essentially a class that can run some piece of code with a set interval and decrement a set countdown every interval tick.
The code will always run with the server's scheduler and thus run on the server's main thread, so you can freely call any synchronous server API.
If you are not looking to create a countdown, but rather only a task that repeats execution every set interval, please check out repeatable tasks.
A countdown task is a class that extends VitalCountdownTask and is annotated with @VitalCountdownTask.Info.
At its core, a countdown task is just a normal repeatable task with an additional countdown and some more lifecycles.
By default, a countdown task will not be a Spring bean. That means that Vital will not automatically create an instance of it.
This is because countdown tasks are also meant to be used by vital-minigames, where each instanced-game may have multiple running countdowns that are not scoped to the entire server.
If you are not making an instanced-game using vital-minigames, you can safely declare your countdown task as a @Component.
@VitalCountdownTask.Info(interval = 1_000, countdown = 10, autoStart = false)
public class MyCountdownTask extends VitalCountdownTask.Spigot {
public MyCountdownTask(JavaPlugin plugin) {
super(plugin);
}
}
A countdown task can be marked as "autoStart" to automatically start it when a new instance is created. This functionality is disabled by default.
The info annotation provides the preferred interval and countdown this task should run at in millis.
On every tick, this task decrements the initial countdown provided in the info annotation.
Once it hits 0, this task will stop.
Lifecycles
| Lifecycle | Usage |
|---|---|
onStart() | Perform an action when this task is started. |
onTick() | Perform an action when this task ticks (Called every configured interval). |
onExpire() | Perform an action when this task's countdown expires. |
onReset() | Perform an action when this task's countdown is reset back to its initial value. |
onRestart() | Perform an action when this task is restarted. |
onStop() | Perform an action when this task is stopped. |