Package com.petarmc.petarlib.cooldowns
Class CooldownManager
java.lang.Object
com.petarmc.petarlib.cooldowns.CooldownManager
Per-player cooldowns.
Stores expiration timestamps (System.currentTimeMillis) and cleans expired entries on read.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckAndTriggerEnd(UUID playerId, String cooldownId) Checks a single cooldown for expiry, calls CooldownEndEvent, and removes it if expired.booleancheckAndTriggerEnd(org.bukkit.entity.Player player, String cooldownId) Player overload ofcheckAndTriggerEnd(UUID, String).static StringformatRemaining(long ms) Formats a remaining duration into mm:ss (zero-padded) format.longgetRemaining(UUID playerId, String cooldownId) Returns remaining cooldown time in milliseconds for the given player and ID.longgetRemaining(org.bukkit.entity.Player player, String cooldownId) Player overload ofgetRemaining(UUID, String).booleanisOnCooldown(UUID playerId, String cooldownId) Checks if the given player is still on the specified cooldown.booleanisOnCooldown(org.bukkit.entity.Player player, String cooldownId) Player overload ofisOnCooldown(UUID, String).voidremoveCooldown(UUID playerId, String cooldownId) Removes a specific cooldown for a player, if present.voidsetCooldown(UUID playerId, String cooldownId, long durationMs) Sets a cooldown for the given player and ID using the supplied duration.voidsetCooldown(org.bukkit.entity.Player player, String cooldownId, long durationMs) Player overload ofsetCooldown(UUID, String, long).
-
Constructor Details
-
CooldownManager
public CooldownManager()
-
-
Method Details
-
isOnCooldown
Checks if the given player is still on the specified cooldown.- Parameters:
playerId- player UUIDcooldownId- logical cooldown identifier- Returns:
trueif cooldown exists and has not expired
-
isOnCooldown
Player overload ofisOnCooldown(UUID, String).- Parameters:
player- Bukkit player (ignored if null)cooldownId- logical cooldown identifier- Returns:
trueif cooldown exists and has not expired
-
getRemaining
Returns remaining cooldown time in milliseconds for the given player and ID. Expired or missing cooldowns return 0 and are pruned from storage. Calls CooldownEndEvent when an expiration is detected.- Parameters:
playerId- player UUIDcooldownId- logical cooldown identifier- Returns:
- remaining time in ms, or 0 if expired/missing
-
getRemaining
Player overload ofgetRemaining(UUID, String).- Parameters:
player- Bukkit player (ignored if null)cooldownId- logical cooldown identifier- Returns:
- remaining time in ms, or 0 if expired/missing
-
setCooldown
Sets a cooldown for the given player and ID using the supplied duration. Calls CooldownStartEvent; if cancelled, no cooldown is stored.- Parameters:
playerId- player UUIDcooldownId- logical cooldown identifierdurationMs- duration in milliseconds (ignored if non-positive)
-
setCooldown
Player overload ofsetCooldown(UUID, String, long).- Parameters:
player- Bukkit player (ignored if null)cooldownId- logical cooldown identifierdurationMs- duration in milliseconds (ignored if non-positive)
-
removeCooldown
Removes a specific cooldown for a player, if present. Does not call end events; intended for manual invalidation.- Parameters:
playerId- player UUIDcooldownId- logical cooldown identifier
-
checkAndTriggerEnd
Checks a single cooldown for expiry, calls CooldownEndEvent, and removes it if expired.- Parameters:
playerId- player UUIDcooldownId- logical cooldown identifier- Returns:
- true if cooldown existed and was expired/removed
-
checkAndTriggerEnd
Player overload ofcheckAndTriggerEnd(UUID, String).- Parameters:
player- Bukkit player (ignored if null)cooldownId- logical cooldown identifier- Returns:
- true if cooldown existed and was expired/removed
-
formatRemaining
Formats a remaining duration into mm:ss (zero-padded) format.- Parameters:
ms- duration in milliseconds- Returns:
- formatted time, or 00:00 when non-positive
-