Class ServerScheduler
java.lang.Object
dev.bouncingelf10.timelesslib.api.scheduler.ServerScheduler
General-purpose task scheduler running against the
Obtain the shared instance through
MinecraftServer context - one-off delays,
repeating tasks, and step sequences. For counting down to zero with rich tick/finish/threshold events,
see ServerCountdownManager instead. Obtain the shared instance through
TimelessLib.scheduler() - this class cannot be constructed by other mods.-
Constructor Summary
ConstructorsConstructorDescriptionServerScheduler(InternalAccess access, Supplier<net.minecraft.server.MinecraftServer> contextProvider) ServerScheduler(InternalAccess access, Supplier<net.minecraft.server.MinecraftServer> contextProvider, dev.bouncingelf10.timelesslib.api.scheduler.Scheduler.Config config) -
Method Summary
Modifier and TypeMethodDescriptionintSchedules a task to run after the specified delay.Schedules a task to run after the specified delay.Schedules a task to run after the specified delay.after(net.minecraft.resources.Identifier id, Duration delay, Consumer<net.minecraft.server.MinecraftServer> task) Schedules a task to run after the specified delay.afterAsync(Duration delay, Consumer<net.minecraft.server.MinecraftServer> task) Schedules a task to run after the specified delay, returning aCompletableFuturethat completes when the task has finished executing.booleanCancels every currently active task and sequence.Schedules a repeating task to run at the specified interval.Schedules a repeating task to run at the specified interval.everyFixedRate(Duration period, Runnable task) Schedules a repeating task to run at the specified interval, with a fixed delay between runs.
E.g.everyFixedRate(Duration period, Consumer<net.minecraft.server.MinecraftServer> task) Schedules a repeating task to run at the specified interval, with a fixed delay between runs.
E.g.get(net.minecraft.resources.Identifier id) Looks up an active task (or sequence) by its ID.booleanbooleanSequence<net.minecraft.server.MinecraftServer> sequence()Starts building a sequence of delayed steps that run one after another - "wait, then do this, then wait, then do that".voidshutdown()If you're getting the scheduler throughTimelessLib.scheduler()or the client counterpart you should NOT call this method.voidshutdownGracefully(long timeout, TimeUnit unit) If you're getting the scheduler throughTimelessLib.scheduler()or the client counterpart you should NOT call this method.
-
Constructor Details
-
ServerScheduler
public ServerScheduler(InternalAccess access, Supplier<net.minecraft.server.MinecraftServer> contextProvider) -
ServerScheduler
public ServerScheduler(InternalAccess access, Supplier<net.minecraft.server.MinecraftServer> contextProvider, dev.bouncingelf10.timelesslib.api.scheduler.Scheduler.Config config)
-
-
Method Details
-
after
Schedules a task to run after the specified delay.- Parameters:
delay- Delay before running the tasktask- Task to run- Returns:
TaskHandle
-
after
Schedules a task to run after the specified delay.- Parameters:
delay- Delay before running the tasktask- Task to run- Returns:
TaskHandle
-
after
public TaskHandle after(net.minecraft.resources.Identifier id, Duration delay, Consumer<net.minecraft.server.MinecraftServer> task) Schedules a task to run after the specified delay.- Parameters:
id- Unique ID for the taskdelay- Delay before running the tasktask- Task to run- Returns:
TaskHandle- Throws:
IllegalArgumentException- if a task with the specified ID already exists
-
after
Schedules a task to run after the specified delay.- Parameters:
id- Unique ID for the taskdelay- Delay before running the tasktask- Task to run- Returns:
TaskHandle- Throws:
IllegalArgumentException- if a task with the specified ID already exists
-
every
Schedules a repeating task to run at the specified interval.- Parameters:
period- Interval between runstask- Task to run- Returns:
TaskHandle
-
every
Schedules a repeating task to run at the specified interval.- Parameters:
period- Interval between runstask- Task to run- Returns:
TaskHandle
-
everyFixedRate
public TaskHandle everyFixedRate(Duration period, Consumer<net.minecraft.server.MinecraftServer> task) Schedules a repeating task to run at the specified interval, with a fixed delay between runs.
E.g.every(Duration, Consumer)will run the interval after the task has finished executing, whereas this method will run the interval immediately after the task starts executing.- Parameters:
period- Interval between runstask- Task to run- Returns:
TaskHandle
-
everyFixedRate
Schedules a repeating task to run at the specified interval, with a fixed delay between runs.
E.g.every(Duration, Runnable)will run the interval after the task has finished executing, whereas this method will run the interval immediately after the task starts executing.- Parameters:
period- Interval between runstask- Task to run- Returns:
TaskHandle
-
afterAsync
public CompletableFuture<Void> afterAsync(Duration delay, Consumer<net.minecraft.server.MinecraftServer> task) Schedules a task to run after the specified delay, returning aCompletableFuturethat completes when the task has finished executing.- Parameters:
delay- Delay before running the tasktask- Task to run- Returns:
CompletableFuture
-
sequence
-
get
Looks up an active task (or sequence) by its ID.- Parameters:
id- Task ID- Returns:
TaskHandleor empty if no active task has that ID
-
activeTaskCount
public int activeTaskCount()- Returns:
- the number of currently active tasks and sequences.
-
cancelAll
public boolean cancelAll()Cancels every currently active task and sequence.- Returns:
- true if at least one task was cancelled
-
shutdown
public void shutdown()If you're getting the scheduler throughTimelessLib.scheduler()or the client counterpart you should NOT call this method. -
shutdownGracefully
If you're getting the scheduler throughTimelessLib.scheduler()or the client counterpart you should NOT call this method.- Throws:
InterruptedException
-
isShutdown
public boolean isShutdown() -
isTerminated
public boolean isTerminated()
-