Class TaskUtil

java.lang.Object
net.mathias2246.buildmc.util.TaskUtil

public final class TaskUtil extends Object
Utility methods for safely scheduling tasks on the main server thread.

These helpers are primarily used to ensure event ordering consistency between different Bukkit events that may fire within the same tick. For example, PlayerInteractEvent may occur before PlayerDropItemEvent, so deferring logic to the next tick guarantees that all other synchronous event handlers have completed first.

Usage example:


 TaskUtil.defer(plugin, () -> {
     if (!ItemDropTracker.droppedRecently(player)) {
         handleToolUse(item, event);
     }
 });
 
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    defer(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task)
    Runs the given task on the next tick on the main server thread.
    static void
    later(@NotNull org.bukkit.plugin.Plugin plugin, long delay, @NotNull Runnable task)
    Runs the given task after a specified number of ticks on the main thread.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • defer

      public static void defer(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task)
      Runs the given task on the next tick on the main server thread.

      This is often used to delay execution until after all synchronous event handlers for the current tick have completed.

      Parameters:
      plugin - the owning plugin instance
      task - the task to execute
    • later

      public static void later(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, long delay, @NotNull @NotNull Runnable task)
      Runs the given task after a specified number of ticks on the main thread.
      Parameters:
      plugin - the owning plugin instance
      delay - number of ticks to delay
      task - the task to execute