Package emu.grasscutter.server.scheduler
Class ServerTaskScheduler
java.lang.Object
emu.grasscutter.server.scheduler.ServerTaskScheduler
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancelTask(int taskId) Removes a task from the scheduler.getAsyncTask(int taskId) Gets an async task from the scheduler.getTask(int taskId) Gets a task from the scheduler.voidrunTasks()Ran every server tick.intscheduleAsyncTask(Runnable runnable) Schedules a task to be run on a separate thread.intscheduleDelayedRepeatingTask(Runnable runnable, int period, int delay) Schedules a task to be run after the amount of ticks has passed.intscheduleDelayedTask(Runnable runnable, int delay) Schedules a task to be run after the amount of ticks has passed.intscheduleRepeatingTask(Runnable runnable, int period) Schedules a task to be run every amount of ticks.intscheduleTask(Runnable runnable) Schedules a task to be run on the next server tick.
-
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
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
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
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
Schedules a task to be run on the next server tick.- Parameters:
runnable- The runnable to run.- Returns:
- The ID of the task.
-
scheduleDelayedTask
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
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
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.
-