Class CooldownManager
java.lang.Object
me.mehboss.utils.CooldownManager
Manages cooldown timers for players on a per-recipe basis.
This class tracks cooldowns using a nested map structure:
Player UUID → (Recipe ID → Cooldown instance)It supports:
- Adding cooldowns
- Checking active cooldowns
- Auto-removing expired cooldowns
- Saving and restoring cooldown data
- Querying remaining cooldown time
CooldownManager.Cooldown inner class.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a cooldown timer for a specific recipe. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCooldown(UUID player, CooldownManager.Cooldown cd) Adds a cooldown for a specific player.voidCleans all expired cooldowns from memory.getCooldown(UUID player, String recipeID) Retrieves a cooldown for a player and recipe.longgetTimeLeft(UUID player, String recipeID) Gets the number of seconds left on a cooldown.booleanhasCooldown(UUID player, String recipeID) Checks whether a cooldown is active for the given player and recipe.voidremoveCooldown(UUID player, String recipeID) Removes a cooldown for a specific recipe and player.voidRestores cooldowns from a saved map.
-
Constructor Details
-
CooldownManager
public CooldownManager()
-
-
Method Details
-
addCooldown
Adds a cooldown for a specific player.- Parameters:
player- The player UUID.cd- The cooldown to apply.
-
getCooldown
Retrieves a cooldown for a player and recipe.- Parameters:
player- The player UUID.recipeID- The ID of the recipe.- Returns:
- The cooldown, or
nullif none exists.
-
hasCooldown
Checks whether a cooldown is active for the given player and recipe.This method automatically removes expired cooldowns.
- Parameters:
player- The player UUID.recipeID- The recipe ID.- Returns:
trueif the cooldown exists and is still active.
-
removeCooldown
-
getTimeLeft
-
cleanExpired
public void cleanExpired()Cleans all expired cooldowns from memory.Useful for periodic cleanup tasks.
-
getCooldowns
-
setCooldowns
Restores cooldowns from a saved map.Existing cooldowns are wiped and replaced.
- Parameters:
map- Cooldowns previously saved.
-