Package net.minestom.server.utils.time
Class Cooldown
java.lang.Object
net.minestom.server.utils.time.Cooldown
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a cooldown with a measurement unit ofChronoUnit.MILLISCooldown(@NotNull Duration duration, @NotNull TemporalUnit temporalUnit) Creates a cooldown with a given unit of measurement. -
Method Summary
Modifier and TypeMethodDescription@NotNull TemporalUnitstatic booleanhasCooldown(long currentTime, long lastUpdate, @NotNull Duration duration) Gets if something is in cooldown based on acurrentTime.static booleanhasCooldown(long currentTime, long lastUpdate, @NotNull TemporalUnit cooldownUnit, long cooldown) Gets if something is in cooldown based on acurrentTime.static booleanhasCooldown(long lastUpdate, @NotNull TemporalUnit temporalUnit, int cooldown) Gets if something is in cooldown based on the current time (System.nanoTime()).static booleanhasCooldown(@NotNull TemporalUnit temporalUnit, long currentTime, long lastUpdate, @NotNull Duration duration) Gets if something is in cooldown based on acurrentTime.static booleanhasCooldown(@NotNull TemporalUnit temporalUnit, long currentTime, long lastUpdate, @NotNull TemporalUnit cooldownUnit, long cooldown) Gets if something is in cooldown based on acurrentTime.booleanisReady(long time) Checks if the cooldown is ready againvoidrefreshLastUpdate(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, @NotNull @NotNull 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
public static boolean hasCooldown(long currentTime, long lastUpdate, @NotNull @NotNull Duration duration) 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(@NotNull @NotNull TemporalUnit temporalUnit, long currentTime, long lastUpdate, @NotNull @NotNull TemporalUnit cooldownUnit, long cooldown) Gets if something is in cooldown based on acurrentTime.- Parameters:
temporalUnit- theTemporalUnitofcurrentTimeandlastUpdatecurrentTime- 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(@NotNull @NotNull TemporalUnit temporalUnit, long currentTime, long lastUpdate, @NotNull @NotNull Duration duration) Gets if something is in cooldown based on acurrentTime.- Parameters:
temporalUnit- theTemporalUnitofcurrentTimeandlastUpdatecurrentTime- the current time in the giventemporalUnitlastUpdate- the last update in the giventemporalUnitduration- the cooldown- Returns:
- true if the cooldown is in progress, false otherwise
-
hasCooldown
public static boolean hasCooldown(long lastUpdate, @NotNull @NotNull TemporalUnit temporalUnit, int cooldown) 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
-