Skip to content
Larrox edited this page Aug 29, 2025 · 3 revisions

The TaskUtil is a utility in LarroxUtilsAPI that allows you to easily schedule tasks on the Bukkit main thread.
It supports running tasks immediately, with a delay, or repeatedly in customizable time intervals.


Note

Don’t forget to import!

import dev.larrox.TaskUtil;

Don’t forget to load it!

TaskUtil taskUtil = new TaskUtil(MAIN_CLASS);

🚀 Features

  • Run tasks instantly on the main thread.
  • Schedule tasks with delays (seconds, minutes, hours, days).
  • Schedule repeating tasks with flexible intervals.

🛠️ Examples

Run a task immediately on the main thread

taskUtil.run(() -> {
    Bukkit.broadcastMessage("This runs instantly!");
});

Run a task once after 1 minute

taskUtil.runLater(() -> {
    Bukkit.broadcastMessage("1 minute has passed!");
}, 0, 0, 1, 0, 0);

Run a task once after 2 days and 5 seconds

taskUtil.runLater(() -> {
    Bukkit.broadcastMessage("2 days and 5 seconds later...");
}, 2, 0, 0, 5, 0);

Run a repeating task: start after 10 seconds, repeat every 5 seconds

taskUtil.runTimer(() -> {
    Bukkit.broadcastMessage("Repeating every 5 seconds!");
}, 0, 0, 0, 10, 0,
   0, 0, 0, 5, 0);

Run a repeating task: start after 1 hour, repeat every 1 day

taskUtil.runTimer(() -> {
    Bukkit.broadcastMessage("This message shows once per day!");
}, 0, 1, 0, 0, 0,
   1, 0, 0, 0, 0);

✅ Best Practices

  • Use run() for instant execution on the main thread.
  • Use runLater() for delayed single runs.
  • Use runTimer() for scheduled repeating tasks.
  • Always initialize TaskUtil with your plugin’s main class (JavaPlugin instance).

Clone this wiki locally