BlurpScheduler

BlurpScheduler is a flexible utility class for scheduling tasks in plugins. It provides a builder-style API to easily configure delayed, repeating, synchronous, or asynchronous tasks, w

Features

  • Builder-style configuration for scheduling tasks

  • Supports delayed and repeating execution

  • Synchronous and asynchronous execution modes

  • Optional onComplete callback after task(s) finish

  • Easy cancellation of running tasks

Usage

Basic Example

new BlurpScheduler()
    .after(40) // Delay in ticks (2 seconds)
    .run(() -> {
        // Your code here
    });

Repeating Task Example

new BlurpScheduler()
    .after(20)      // Initial delay (1 second)
    .repeat(5)      // Repeat 5 times
    .period(10)     // Every 10 ticks (0.5 seconds)
    .onComplete(() -> {
        // Code to run after all repeats
    })
    .run(() -> {
        // Code to run each time
    });

Asynchronous Example

new BlurpScheduler()
    .async()
    .after(0)
    .repeat(3)
    .period(20)
    .run(() -> {
        // Async code here
    });

Cancelling a Task

BlurpScheduler scheduler = new BlurpScheduler();
scheduler.repeat(100).run(() -> {
    // ...
});
// Later, to cancel:
scheduler.cancel();

API Reference

Method
Description

after(int ticks)

Delay before first execution

repeat(int times)

Number of times to repeat the task

period(int ticks)

Interval between repeats (default: 1 tick)

async()

Run the task asynchronously

onComplete(Runnable)

Callback after all repeats finish/cancelled

run(Runnable)

Start the scheduled task

cancel()

Cancel the running task

Notes

  • All time values are in ticks (20 ticks = 1 second).

  • If repeat or period are not set, the task runs only once after the delay.

  • Use async() for non-blocking/background operations.

Last updated