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>
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
ConstructorsConstructorDescriptionTickCoolDownHandler
(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 TypeMethodDescriptionlong
Retrieves the remaining cooldown time for the specified object.long
Returns the total maximum cooldown duration set for this handler.boolean
onCoolDown
(E e) Checks if the specified object is currently on cooldown.void
putOnCoolDown
(E e) Sets the cooldown to its maximum duration for the specified object.void
removeCooldown
(E e) Removes the cooldown for the specified object, effectively resetting its cooldown status.
-
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
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 interfaceICoolDownHandler<E>
- Parameters:
e
- The object to set the cooldown for.
-
onCoolDown
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 interfaceICoolDownHandler<E>
- Parameters:
e
- The object to check.- Returns:
- True if the object is on cooldown, false otherwise.
-
getRemainingCoolDown
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 interfaceICoolDownHandler<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 interfaceICoolDownHandler<E>
- Returns:
- The maximum cooldown duration for this handler.
-
removeCooldown
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 interfaceICoolDownHandler<E>
- Parameters:
e
- The object for which to remove the cooldown.
-