Class Cooldown

java.lang.Object
net.minestom.server.utils.time.Cooldown

public final class Cooldown extends Object
  • Constructor Details

    • Cooldown

      public Cooldown(Duration duration)
      Creates a cooldown with a measurement unit of ChronoUnit.MILLIS
    • Cooldown

      public Cooldown(Duration duration, TemporalUnit temporalUnit)
      Creates a cooldown with a given unit of measurement.

      All calls to refreshLastUpdate(long) and isReady(long) must pass values in the given unit.

      Parameters:
      duration - the duration of the cooldown
      temporalUnit - the unit of measurement
  • Method Details

    • getTemporalUnit

      public TemporalUnit getTemporalUnit()
      Returns:
      the unit of measurement
    • getDuration

      public Duration 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 a currentTime.
      Parameters:
      currentTime - the current time in milliseconds
      lastUpdate - the last update in milliseconds
      cooldownUnit - the time unit of the cooldown
      cooldown - the value of the cooldown
      Returns:
      true if the cooldown is in progress, false otherwise
    • hasCooldown

      public static boolean hasCooldown(long currentTime, long lastUpdate, Duration duration)
      Gets if something is in cooldown based on a currentTime.
      Parameters:
      currentTime - the current time in milliseconds
      lastUpdate - the last update in milliseconds
      duration - 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 a currentTime.
      Parameters:
      temporalUnit - the TemporalUnit of currentTime and lastUpdate
      currentTime - the current time in milliseconds
      lastUpdate - the last update in milliseconds
      cooldownUnit - the time unit of the cooldown
      cooldown - 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 a currentTime.
      Parameters:
      temporalUnit - the TemporalUnit of currentTime and lastUpdate
      currentTime - the current time in the given temporalUnit
      lastUpdate - the last update in the given temporalUnit
      duration - the cooldown
      Returns:
      true if the cooldown is in progress, false otherwise
    • hasCooldown

      public static boolean hasCooldown(long lastUpdate, TemporalUnit temporalUnit, int cooldown)
      Gets if something is in cooldown based on the current time (System.nanoTime()).
      Parameters:
      lastUpdate - the last update in System.nanoTime()
      temporalUnit - the time unit of the cooldown
      cooldown - the value of the cooldown
      Returns:
      true if the cooldown is in progress, false otherwise