Package dev.demeng.pluginbase.cooldown
Class Cooldown
java.lang.Object
dev.demeng.pluginbase.cooldown.Cooldown
A cooldown lasting a specified amount of time.
-
Method Summary
Modifier and TypeMethodDescription@NotNull Cooldowncopy()Copies the properties of this cooldown to a new instancelongelapsed()Returns the elapsed time in milliseconds since the cooldown was last reset, or since creation time.@NotNull OptionalLongReturn the time in milliseconds when this cooldown was lasttest()ed.static @NotNull CooldownCreates a cooldown lasting a specified amount of time.static @NotNull CooldownofTicks(long ticks) Creates a cooldown lasting a number of game ticks.longGets the time in milliseconds until the cooldown will become inactive.longremainingTime(TimeUnit unit) Gets the time until the cooldown will become inactive.voidreset()Resets the cooldown.voidsetLastTested(long time) Sets the time in milliseconds when this cooldown was last tested.booleantest()Returns true if the cooldown is not active, and then resets the timer.booleanReturns true if the cooldown is not active.
-
Method Details
-
ofTicks
Creates a cooldown lasting a number of game ticks.- Parameters:
ticks- The number of ticks- Returns:
- The new Cooldown
-
of
Creates a cooldown lasting a specified amount of time.- Parameters:
amount- The amount of timeunit- The unit of time- Returns:
- The new Cooldown
-
test
public boolean test()Returns true if the cooldown is not active, and then resets the timer.If the cooldown is currently active, the timer is not reset.
- Returns:
- true if the cooldown is not active
-
testSilently
public boolean testSilently()Returns true if the cooldown is not active.- Returns:
- true if the cooldown is not active
-
elapsed
public long elapsed()Returns the elapsed time in milliseconds since the cooldown was last reset, or since creation time.- Returns:
- The elapsed time
-
reset
public void reset()Resets the cooldown. -
remainingMillis
public long remainingMillis()Gets the time in milliseconds until the cooldown will become inactive.If the cooldown is not active, this method returns
0.- Returns:
- The time in millis until the cooldown will expire
-
remainingTime
Gets the time until the cooldown will become inactive.If the cooldown is not active, this method returns
0.- Parameters:
unit- The unit to return in- Returns:
- The time until the cooldown will expire
-
getLastTested
Return the time in milliseconds when this cooldown was lasttest()ed.- Returns:
- The last call time
-
setLastTested
public void setLastTested(long time) Sets the time in milliseconds when this cooldown was last tested.Note: this should only be used when re-constructing a cooldown instance. Use
test()otherwise.- Parameters:
time- The time
-
copy
Copies the properties of this cooldown to a new instance- Returns:
- A cloned Cooldown instance
-