Class ServerScheduler

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

public class ServerScheduler 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 Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Cancel all pending or happening tasks that have the given owner tag.
    static void
    schedule(int ticks, Runnable task)
    Schedules a task to be executed after a specified time in ticks.
    static void
    schedule(int ticks, Runnable task, String owner)
    Schedules a task to be executed after a specified time in ticks.
    static void
    Advances the countdown for all registered tasks and execute the tasks when the countdown reaches zero.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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.
    • 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 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.