java.lang.Object
net.minestom.server.utils.time.Cooldown
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a cooldown with a measurement unit ofChronoUnit.MILLIS
Cooldown
(Duration duration, TemporalUnit temporalUnit) Creates a cooldown with a given unit of measurement. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
hasCooldown
(long currentTime, long lastUpdate, Duration duration) Gets if something is in cooldown based on acurrentTime
.static boolean
hasCooldown
(long currentTime, long lastUpdate, TemporalUnit cooldownUnit, long cooldown) Gets if something is in cooldown based on acurrentTime
.static boolean
hasCooldown
(long lastUpdate, TemporalUnit temporalUnit, int cooldown) Gets if something is in cooldown based on the current time (System.nanoTime()
).static boolean
hasCooldown
(TemporalUnit temporalUnit, long currentTime, long lastUpdate, Duration duration) Gets if something is in cooldown based on acurrentTime
.static boolean
hasCooldown
(TemporalUnit temporalUnit, long currentTime, long lastUpdate, TemporalUnit cooldownUnit, long cooldown) Gets if something is in cooldown based on acurrentTime
.boolean
isReady
(long time) Checks if the cooldown is ready againvoid
refreshLastUpdate
(long lastUpdate)
-
Constructor Details
-
Cooldown
Creates a cooldown with a measurement unit ofChronoUnit.MILLIS
-
Cooldown
Creates a cooldown with a given unit of measurement.All calls to
refreshLastUpdate(long)
andisReady(long)
must pass values in the given unit.- Parameters:
duration
- the duration of the cooldowntemporalUnit
- the unit of measurement
-
-
Method Details
-
getTemporalUnit
- Returns:
- the unit of measurement
-
getDuration
-
refreshLastUpdate
public void refreshLastUpdate(long lastUpdate) - Parameters:
lastUpdate
- the time of the last update, in nanos
-
isReady
public boolean isReady(long time) Checks if the cooldown is ready again- Parameters:
time
- the time, in nanos
-
hasCooldown
public static boolean hasCooldown(long currentTime, long lastUpdate, TemporalUnit cooldownUnit, long cooldown) Gets if something is in cooldown based on acurrentTime
.- Parameters:
currentTime
- the current time in millisecondslastUpdate
- the last update in millisecondscooldownUnit
- the time unit of the cooldowncooldown
- the value of the cooldown- Returns:
- true if the cooldown is in progress, false otherwise
-
hasCooldown
Gets if something is in cooldown based on acurrentTime
.- Parameters:
currentTime
- the current time in millisecondslastUpdate
- the last update in millisecondsduration
- the cooldown- Returns:
- true if the cooldown is in progress, false otherwise
-
hasCooldown
public static boolean hasCooldown(TemporalUnit temporalUnit, long currentTime, long lastUpdate, TemporalUnit cooldownUnit, long cooldown) Gets if something is in cooldown based on acurrentTime
.- Parameters:
temporalUnit
- theTemporalUnit
ofcurrentTime
andlastUpdate
currentTime
- the current time in millisecondslastUpdate
- the last update in millisecondscooldownUnit
- the time unit of the cooldowncooldown
- the value of the cooldown- Returns:
- true if the cooldown is in progress, false otherwise
-
hasCooldown
public static boolean hasCooldown(TemporalUnit temporalUnit, long currentTime, long lastUpdate, Duration duration) Gets if something is in cooldown based on acurrentTime
.- Parameters:
temporalUnit
- theTemporalUnit
ofcurrentTime
andlastUpdate
currentTime
- the current time in the giventemporalUnit
lastUpdate
- the last update in the giventemporalUnit
duration
- the cooldown- Returns:
- true if the cooldown is in progress, false otherwise
-
hasCooldown
Gets if something is in cooldown based on the current time (System.nanoTime()
).- Parameters:
lastUpdate
- the last update inSystem.nanoTime()
temporalUnit
- the time unit of the cooldowncooldown
- the value of the cooldown- Returns:
- true if the cooldown is in progress, false otherwise
-