Class Countdown<T,SELF extends Countdown<T,SELF>>
java.lang.Object
dev.bouncingelf10.timelesslib.api.countdown.Countdown<T,SELF>
- Type Parameters:
T- Context type (e.g. the server or client instance) passed to handlers.SELF- Concrete subtype, so builder-style methods return the right type. SeeServerCountdown/ClientCountdown.
- All Implemented Interfaces:
TaskHandle
- Direct Known Subclasses:
ClientCountdown,ServerCountdown
public abstract class Countdown<T,SELF extends Countdown<T,SELF>>
extends Object
implements TaskHandle
A single countdown-to-zero task, produced by
Implements the same
ServerCountdownManager.start(Duration) / ClientCountdownManager.start(Duration). Implements the same
TaskHandle lifecycle (cancel(), pause(), resume()) as a plain
scheduled task, plus richer countdown-shaped notifications (tick, finish, threshold, custom-interval handlers).-
Method Summary
Modifier and TypeMethodDescriptionbooleancancel()Cancels the countdown.elapsed()Adds a task to execute every time the specified interval elapses.Returns the period of a repeating task.Returns the remaining delay before the next run.net.minecraft.resources.ResourceLocationid()booleanbooleanbooleanisPaused()booleanbooleanAdds a task to execute when the countdown finishes, without needing the context.Adds a task to execute when the countdown finishes.onThreshold(Duration threshold, Consumer<T> handler) Adds a task to execute when the countdown reaches the specified threshold.onTick(BiConsumer<T, Duration> handler) Adds a task to execute every countdown tick specified by the tick interval.Adds a task to execute every countdown tick specified by the tick interval, without needing the context.booleanpause()Pauses the countdown.booleanToggles to pause or unpause the countdown.doubleprogress()booleanresume()Resumes a paused countdown.booleanrunNow()Runs the task immediately if possible.
-
Method Details
-
cancel
public boolean cancel()Cancels the countdown.- Specified by:
cancelin interfaceTaskHandle- Returns:
- true if the countdown was cancelled, false if it was already finished or canceled
-
pause
public boolean pause()Pauses the countdown. Note: If the countdown is already paused, this method does nothing.- Specified by:
pausein interfaceTaskHandle- Returns:
- true if the countdown was paused, false if it was already finished or canceled
-
resume
public boolean resume()Resumes a paused countdown. Note: If the countdown is not paused, this method does nothing.- Specified by:
resumein interfaceTaskHandle- Returns:
- true if the countdown was resumed, false if it was already finished or canceled
-
pauseOrUnpause
public boolean pauseOrUnpause()Toggles to pause or unpause the countdown.- Specified by:
pauseOrUnpausein interfaceTaskHandle- Returns:
- true if the countdown was changed state, false if it was already finished or canceled
-
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceTaskHandle- Returns:
- true if the task has been canceled
-
isPaused
public boolean isPaused()- Specified by:
isPausedin interfaceTaskHandle
-
isFinished
public boolean isFinished() -
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceTaskHandle
-
isScheduled
public boolean isScheduled()- Specified by:
isScheduledin interfaceTaskHandle- Returns:
- true if the task is scheduled for execution
-
getRemainingDelay
Description copied from interface:TaskHandleReturns the remaining delay before the next run.- Specified by:
getRemainingDelayin interfaceTaskHandle- Returns:
- remaining delay, or empty if canceled
-
getPeriod
Description copied from interface:TaskHandleReturns the period of a repeating task.- Specified by:
getPeriodin interfaceTaskHandle- Returns:
- the period, or empty if not repeating
-
runNow
public boolean runNow()Description copied from interface:TaskHandleRuns the task immediately if possible.- Specified by:
runNowin interfaceTaskHandle- Returns:
- true if the task was executed
-
remaining
-
elapsed
- Returns:
- time elapsed since the countdown started, clamped to the total duration.
-
progress
public double progress()- Returns:
- progress from 0.0 (just started) to 1.0 (finished).
-
id
public net.minecraft.resources.ResourceLocation id()- Specified by:
idin interfaceTaskHandle- Returns:
- unique ID of this task
-
onTick
Adds a task to execute every countdown tick specified by the tick interval.- Parameters:
handler- Handler to execute every countdown tick.
-
onTick
Adds a task to execute every countdown tick specified by the tick interval, without needing the context.- Parameters:
handler- Handler to execute every countdown tick.
-
onFinish
Adds a task to execute when the countdown finishes.- Parameters:
handler- Handler to execute when the countdown finishes.
-
onFinish
Adds a task to execute when the countdown finishes, without needing the context.- Parameters:
handler- Handler to execute when the countdown finishes.
-
onThreshold
Adds a task to execute when the countdown reaches the specified threshold.- Parameters:
threshold- Duration threshold to reach.handler- Handler to execute when the threshold is reached.
-
every
Adds a task to execute every time the specified interval elapses. (LikeonTick(BiConsumer), but with a specified interval instead of the countdown tick interval)- Parameters:
interval- Interval at which to execute the handler.handler- Handler to execute every time the interval elapses.
-