VitalRepeatableTask

abstract class VitalRepeatableTask<P, R : Runnable, T>(val plugin: P) : VitalHasInfo

Defines a repeatable task within the Vital framework. A task may perform repeated actions with a set interval.

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.

A repeatable task can be marked as "autoStart" to automatically start it when a new instance is created. This functionality is disabled by default.

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

@Override
public void onTick() {
// ...
}
}

Inheritors

Constructors

Link copied to clipboard
constructor(plugin: P)

Types

Link copied to clipboard
Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class Info(val interval: Long, val autoStart: Boolean = false)

Defines the info for a VitalRepeatableTask.

Link copied to clipboard

Properties

Link copied to clipboard

Controls if this task can currently tick and call the onTick lifecycle function.

Link copied to clipboard
Link copied to clipboard
val plugin: P
Link copied to clipboard
var runnable: R?

The internal task that runs to call the onTick lifecycle function. This field will be null if this task is currently not running.

Link copied to clipboard

Checks if this task is currently running.

Link copied to clipboard
var task: T?

The internal task that's runs the runnable to call the onTick lifecycle function. This field will be null if this task is currently not running.

Functions

Link copied to clipboard
abstract fun cancelRunnable()

Cancels the internal runnable for this task.

Link copied to clipboard
abstract fun cancelTask()

Cancels the internal task for this task.

Link copied to clipboard
abstract fun createRunnable(): R

Creates the internal runnable for this task.

Link copied to clipboard
abstract fun createTask(): T

Creates the internal runnable for this task.

Link copied to clipboard
open fun <T : Annotation> getInfo(type: Class<T>): T
Link copied to clipboard

Handles a single tick of this task and calls the onTick lifecycle function. If ticks are disabled by allowTick, this function does nothing.

Link copied to clipboard
open fun onStart()

Lifecycle function; called when this task is started.

Link copied to clipboard
open fun onStop()

Lifecycle function; called when this task is stopped.

Link copied to clipboard
open fun onTick()

Lifecycle function; called when this task is ticked. This task will only tick if allowTick is true.

Link copied to clipboard
fun start()

Starts this task if It's not already running. This function will call createRunnable and createTask to set up this task before starting the internal tick timer. The onStart lifecycle function will be called after this task is ready for execution.

Link copied to clipboard
fun stop()

Stops this task if It's currently running. This function stops and cleans up the internal runnable and task and then calls the onStop lifecycle function.