Class TickCoolDownHandler<E>

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

public class TickCoolDownHandler<E> extends Object implements ICoolDownHandler<E>
Manages cooldowns for objects based on the game's tick system. Each game tick, the internal counter is incremented, which is used to track cooldowns. This implementation is useful for cooldowns that need to be in sync with the game's tick rate, such as abilities or actions that are used within the game world.
Since:
2023-04-02
Version:
1.0.0
Author:
Maxopoly, notzune
  • Constructor Summary

    Constructors
    Constructor
    Description
    TickCoolDownHandler(org.bukkit.plugin.java.JavaPlugin executingPlugin, long cooldown)
    Initializes a cooldown handler for objects based on ticks, using an internal counter.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Retrieves the remaining cooldown time for the specified object.
    long
    Returns the total maximum cooldown duration set for this handler.
    boolean
    Checks if the specified object is currently on cooldown.
    void
    Sets the cooldown to its maximum duration for the specified object.
    void
    Removes the cooldown for the specified object, effectively resetting its cooldown status.

    Methods inherited from class java.lang.Object

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

    • TickCoolDownHandler

      public TickCoolDownHandler(org.bukkit.plugin.java.JavaPlugin executingPlugin, long cooldown)
      Initializes a cooldown handler for objects based on ticks, using an internal counter.
      Parameters:
      executingPlugin - The JavaPlugin instance that this cooldown handler belongs to.
      cooldown - The duration of the cooldown in ticks.
  • Method Details

    • putOnCoolDown

      public void putOnCoolDown(E e)
      Description copied from interface: ICoolDownHandler
      Sets the cooldown to its maximum duration for the specified object.

      Usage Example:

       
       ICoolDownHandler<Player> playerCooldownHandler = ...;
       playerCooldownHandler.putOnCoolDown(player);
       
       
      Specified by:
      putOnCoolDown in interface ICoolDownHandler<E>
      Parameters:
      e - The object to set the cooldown for.
    • onCoolDown

      public boolean onCoolDown(E e)
      Description copied from interface: ICoolDownHandler
      Checks if the specified object is currently on cooldown.

      Usage Example:

       
       if (playerCooldownHandler.onCoolDown(player)) {
           System.out.println("Player is on cooldown!");
       }
       
       
      Specified by:
      onCoolDown in interface ICoolDownHandler<E>
      Parameters:
      e - The object to check.
      Returns:
      True if the object is on cooldown, false otherwise.
    • getRemainingCoolDown

      public long getRemainingCoolDown(E e)
      Description copied from interface: ICoolDownHandler
      Retrieves the remaining cooldown time for the specified object. The returned value is context-dependent but is always between 0 and the maximum cooldown duration.

      Usage Example:

       
       long remainingTime = playerCooldownHandler.getRemainingCoolDown(player);
       System.out.println("Remaining cooldown time: " + remainingTime);
       
       
      Specified by:
      getRemainingCoolDown in interface ICoolDownHandler<E>
      Parameters:
      e - The object to get the cooldown for.
      Returns:
      The remaining cooldown time for the object, or 0 if there's no active cooldown.
    • getTotalCoolDown

      public long getTotalCoolDown()
      Description copied from interface: ICoolDownHandler
      Returns the total maximum cooldown duration set for this handler. The meaning of this duration is implementation-specific.

      Usage Example:

       
       long totalCooldown = playerCooldownHandler.getTotalCoolDown();
       System.out.println("Total cooldown duration: " + totalCooldown);
       
       
      Specified by:
      getTotalCoolDown in interface ICoolDownHandler<E>
      Returns:
      The maximum cooldown duration for this handler.
    • removeCooldown

      public void removeCooldown(E e)
      Description copied from interface: ICoolDownHandler
      Removes the cooldown for the specified object, effectively resetting its cooldown status.

      Usage Example:

       
       playerCooldownHandler.removeCooldown(player);
       
       
      Specified by:
      removeCooldown in interface ICoolDownHandler<E>
      Parameters:
      e - The object for which to remove the cooldown.