2 minutes estimated read time

Repeatable tasks

A repeatable task is essentially a class that can run some piece of code with a set interval.
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 looking to create a countdown, please check out countdown tasks.


A repeatable task is a class that extends VitalRepeatableTask and is annotated with @VitalRepeatableTask.Info.

By default, a repeatable task will not be a Spring bean. That means that Vital will not automatically create an instance of it.
This is because repeatable tasks are also meant to be used by vital-minigames, where each instanced-game may have multiple running tasks that are not scoped to the entire server.

If you are not making an instanced-game using vital-minigames, you can safely declare your repeatable task as a @Component.

MyRepeatableTask.java
@VitalRepeatableTask.Info(interval = 1_000, autoStart = false)
public class MyRepeatableTask extends VitalRepeatableTask.Spigot {
  public MyRepeatableTask(JavaPlugin plugin) {
    super(plugin);
  }
}

A repeatable 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 this task should run at in millis.

Lifecycles

LifecycleUsage
onStart()Perform an action when this task is started.
onTick()Perform an action when this task ticks (Called every configured interval).
onStop()Perform an action when this task is stopped.

Found an issue?

Help us improve the documentation by reporting typos, missing information, or anything confusing.

Don't worry, we will auto-fill most of the annoying fields.

Create GitHub issue

This site and the Vital framework were built with ❤️ by Mike Neumann