Class ServerScheduler

java.lang.Object
net.kamkeyke.raccooncore.util.ServerScheduler

public class ServerScheduler extends Object
A lightweight, 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

    • ServerScheduler

      public ServerScheduler()
  • 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.
    • tick

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

      This method is invoked internally by RaccoonCore's event handlers 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.