Class ServerScheduler
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcancelAllWithOwner(String owner) Cancel all pending or happening tasks that have the given owner tag.static voidSchedules a task to be executed after a specified time in ticks.static voidSchedules a task to be executed after a specified time in ticks.static voidtick()Advances the countdown for all registered tasks and execute the tasks when the countdown reaches zero.
-
Constructor Details
-
ServerScheduler
public ServerScheduler()
-
-
Method Details
-
schedule
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- TheRunnablecontaining the logic to be executed.
-
schedule
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- TheRunnablecontaining 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
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.
-