Class ServerTaskScheduler

java.lang.Object
emu.grasscutter.server.scheduler.ServerTaskScheduler

public final class ServerTaskScheduler extends Object
A class to manage all time-based tasks scheduled on the server. This handles both synchronous and asynchronous tasks. Developers note: A server tick is ONE REAL-TIME SECOND.
  • Constructor Details

    • ServerTaskScheduler

      public ServerTaskScheduler()
  • Method Details

    • runTasks

      public void runTasks()
      Ran every server tick. Attempts to run all scheduled tasks. This method is synchronous and will block until all tasks are complete.
    • getTask

      public ServerTask getTask(int taskId)
      Gets a task from the scheduler.
      Parameters:
      taskId - The ID of the task to get.
      Returns:
      The task, or null if it does not exist.
    • getAsyncTask

      public AsyncServerTask getAsyncTask(int taskId)
      Gets an async task from the scheduler.
      Parameters:
      taskId - The ID of the task to get.
      Returns:
      The task, or null if it does not exist.
    • cancelTask

      public void cancelTask(int taskId)
      Removes a task from the scheduler.
      Parameters:
      taskId - The ID of the task to remove.
    • scheduleAsyncTask

      public int scheduleAsyncTask(Runnable runnable)
      Schedules a task to be run on a separate thread. The task runs on the next server tick.
      Parameters:
      runnable - The runnable to run.
      Returns:
      The ID of the task.
    • scheduleTask

      public int scheduleTask(Runnable runnable)
      Schedules a task to be run on the next server tick.
      Parameters:
      runnable - The runnable to run.
      Returns:
      The ID of the task.
    • scheduleDelayedTask

      public int scheduleDelayedTask(Runnable runnable, int delay)
      Schedules a task to be run after the amount of ticks has passed.
      Parameters:
      runnable - The runnable to run.
      delay - The amount of ticks to wait before running.
      Returns:
      The ID of the task.
    • scheduleRepeatingTask

      public int scheduleRepeatingTask(Runnable runnable, int period)
      Schedules a task to be run every amount of ticks.
      Parameters:
      runnable - The runnable to run.
      period - The amount of ticks to wait before running again.
      Returns:
      The ID of the task.
    • scheduleDelayedRepeatingTask

      public int scheduleDelayedRepeatingTask(Runnable runnable, int period, int delay)
      Schedules a task to be run after the amount of ticks has passed.
      Parameters:
      runnable - The runnable to run.
      period - The amount of ticks to wait before running again.
      delay - The amount of ticks to wait before running the first time.
      Returns:
      The ID of the task.