Class MilliSecCoolDownHandler<E>

java.lang.Object
tk.airshipcraft.commonlib.utils.cooldowns.MilliSecCoolDownHandler<E>
Type Parameters:
E - The type of object that cooldowns are being tracked for.
All Implemented Interfaces:
ICoolDownHandler<E>

public class MilliSecCoolDownHandler<E> extends Object implements ICoolDownHandler<E>
Manages cooldowns for generic objects with millisecond precision. This handler stores and checks cooldowns based on system time stamps, allowing you to limit actions within a specified cooldown period.
Since:
2023-04-02
Version:
1.0.0
Author:
Maxopoly, notzune
  • Constructor Details

    • MilliSecCoolDownHandler

      public MilliSecCoolDownHandler(long cooldown)
      Initializes a cooldown handler with a specified duration.
      Parameters:
      cooldown - The duration of the cooldown in milliseconds.
  • Method Details

    • putOnCoolDown

      public void putOnCoolDown(E e)
      Puts an object on cooldown, starting from the current system time.
      Specified by:
      putOnCoolDown in interface ICoolDownHandler<E>
      Parameters:
      e - The object to put on cooldown.
    • onCoolDown

      public boolean onCoolDown(E e)
      Checks if an object is currently on cooldown.
      Specified by:
      onCoolDown in interface ICoolDownHandler<E>
      Parameters:
      e - The object to check for cooldown.
      Returns:
      true if the object is on cooldown, false otherwise.
    • getRemainingCoolDown

      public long getRemainingCoolDown(E e)
      Gets the remaining cooldown time for an object.
      Specified by:
      getRemainingCoolDown in interface ICoolDownHandler<E>
      Parameters:
      e - The object to check the cooldown for.
      Returns:
      The remaining cooldown time in milliseconds, or 0 if the object is not on cooldown or the cooldown has expired.
    • getTotalCoolDown

      public long getTotalCoolDown()
      Retrieves the total cooldown duration set for this handler.
      Specified by:
      getTotalCoolDown in interface ICoolDownHandler<E>
      Returns:
      The cooldown duration in milliseconds.
    • removeCooldown

      public void removeCooldown(E e)
      Removes an object from the cooldown tracking, effectively resetting its cooldown status.
      Specified by:
      removeCooldown in interface ICoolDownHandler<E>
      Parameters:
      e - The object to remove from cooldown tracking.