Class ServerTaskScheduler

java.lang.Object
net.kamkeyke.raccooncore.misc.scheduler.ServerTaskScheduler

public class ServerTaskScheduler extends Object
A tick-based task scheduler for the server environment.

This utility allows developers to defer task execution for a specific number of game ticks. It runs exclusively on the server's main thread, making it safe for world, entity, and block manipulations.

Implementation Note: This scheduler is automatically managed by the RaccoonCore. Never manually call tick() if this mod is active, as it is already called by the mod in the TickEvent.ServerTickEvent.

  • Constructor Details

    • ServerTaskScheduler

      public ServerTaskScheduler()
  • Method Details

    • schedule

      public static void schedule(int ticks, Runnable task)
      Schedules a task to be executed after a specified time in ticks.
      Parameters:
      ticks - Time in game ticks that the task should wait before being executed (e.g., 20 ticks = 1 second).
      task - The Runnable containing the logic to be executed.
    • schedule

      public static void schedule(int ticks, Runnable task, String owner)
      Schedules a task to be executed after a specified time in ticks.
      Parameters:
      ticks - Time in game ticks that the task should wait before being executed (e.g., 20 ticks = 1 second).
      task - The Runnable containing the logic to be executed.
      owner - Optional owner tag that can be used to cancel all tasks with that same owner.

      Note: owner doesn't have to be a modid or player name. Any name will do, as long the other correlated tasks have the same owner tag.

    • cancelAllWithOwner

      public static void cancelAllWithOwner(String owner)
      Cancel all pending or happening tasks that have the given owner tag.
      Parameters:
      owner - owner tag
    • tick

      public static void tick()
      Advances the countdown for all registered tasks and execute the tasks when the countdown reaches zero.

      This method is normally invoked internally by RaccoonCore's server tick event handler and should NOT be called manually when RaccoonCore is active.

      During the server tick, when a task's timer reaches zero, it is executed and removed from the queue. Exceptions within tasks are caught and logged to prevent server-side crashes.