Class Cooldown

java.lang.Object
dev.demeng.pluginbase.cooldown.Cooldown

public class Cooldown extends Object
A cooldown lasting a specified amount of time.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull Cooldown
    Copies the properties of this cooldown to a new instance
    long
    Returns the elapsed time in milliseconds since the cooldown was last reset, or since creation time.
    @NotNull OptionalLong
    Return the time in milliseconds when this cooldown was last test()ed.
    static @NotNull Cooldown
    of(long amount, @NotNull TimeUnit unit)
    Creates a cooldown lasting a specified amount of time.
    static @NotNull Cooldown
    ofTicks(long ticks)
    Creates a cooldown lasting a number of game ticks.
    long
    Gets the time in milliseconds until the cooldown will become inactive.
    long
    Gets the time until the cooldown will become inactive.
    void
    Resets the cooldown.
    void
    setLastTested(long time)
    Sets the time in milliseconds when this cooldown was last tested.
    boolean
    Returns true if the cooldown is not active, and then resets the timer.
    boolean
    Returns true if the cooldown is not active.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • ofTicks

      @NotNull public static @NotNull Cooldown ofTicks(long ticks)
      Creates a cooldown lasting a number of game ticks.
      Parameters:
      ticks - The number of ticks
      Returns:
      The new Cooldown
    • of

      @NotNull public static @NotNull Cooldown of(long amount, @NotNull @NotNull TimeUnit unit)
      Creates a cooldown lasting a specified amount of time.
      Parameters:
      amount - The amount of time
      unit - 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

      public long remainingTime(TimeUnit unit)
      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

      @NotNull public @NotNull OptionalLong getLastTested()
      Return the time in milliseconds when this cooldown was last test()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

      @NotNull public @NotNull Cooldown copy()
      Copies the properties of this cooldown to a new instance
      Returns:
      A cloned Cooldown instance