Class TaskUtil
java.lang.Object
net.mathias2246.buildmc.util.TaskUtil
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 TypeMethodDescriptionstatic voidRuns the given task on the next tick on the main server thread.static voidRuns the given task after a specified number of ticks on the main thread.
-
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 instancetask- 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 instancedelay- number of ticks to delaytask- the task to execute
-