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>
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 Summary
ConstructorsConstructorDescriptionMilliSecCoolDownHandler
(long cooldown) Initializes a cooldown handler with a specified duration. -
Method Summary
Modifier and TypeMethodDescriptionlong
Gets the remaining cooldown time for an object.long
Retrieves the total cooldown duration set for this handler.boolean
onCoolDown
(E e) Checks if an object is currently on cooldown.void
putOnCoolDown
(E e) Puts an object on cooldown, starting from the current system time.void
removeCooldown
(E e) Removes an object from the cooldown tracking, effectively resetting its cooldown status.
-
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
Puts an object on cooldown, starting from the current system time.- Specified by:
putOnCoolDown
in interfaceICoolDownHandler<E>
- Parameters:
e
- The object to put on cooldown.
-
onCoolDown
Checks if an object is currently on cooldown.- Specified by:
onCoolDown
in interfaceICoolDownHandler<E>
- Parameters:
e
- The object to check for cooldown.- Returns:
- true if the object is on cooldown, false otherwise.
-
getRemainingCoolDown
Gets the remaining cooldown time for an object.- Specified by:
getRemainingCoolDown
in interfaceICoolDownHandler<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 interfaceICoolDownHandler<E>
- Returns:
- The cooldown duration in milliseconds.
-
removeCooldown
Removes an object from the cooldown tracking, effectively resetting its cooldown status.- Specified by:
removeCooldown
in interfaceICoolDownHandler<E>
- Parameters:
e
- The object to remove from cooldown tracking.
-