Class CooldownManager

java.lang.Object
me.mehboss.utils.CooldownManager

public class CooldownManager extends Object
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
Cooldowns are represented by the CooldownManager.Cooldown inner class.
  • Constructor Details

    • CooldownManager

      public CooldownManager()
  • Method Details

    • addCooldown

      public void addCooldown(UUID player, CooldownManager.Cooldown cd)
      Adds a cooldown for a specific player.
      Parameters:
      player - The player UUID.
      cd - The cooldown to apply.
    • getCooldown

      public CooldownManager.Cooldown getCooldown(UUID player, String recipeID)
      Retrieves a cooldown for a player and recipe.
      Parameters:
      player - The player UUID.
      recipeID - The ID of the recipe.
      Returns:
      The cooldown, or null if none exists.
    • hasCooldown

      public boolean hasCooldown(UUID player, String recipeID)
      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:
      true if the cooldown exists and is still active.
    • removeCooldown

      public void removeCooldown(UUID player, String recipeID)
      Removes a cooldown for a specific recipe and player.
      Parameters:
      player - The player UUID.
      recipeID - The recipe ID to remove.
    • getTimeLeft

      public long getTimeLeft(UUID player, String recipeID)
      Gets the number of seconds left on a cooldown.

      Automatically clears expired cooldowns.

      Parameters:
      player - The player UUID.
      recipeID - The recipe ID.
      Returns:
      Seconds remaining, or 0 if expired or not found.
    • cleanExpired

      public void cleanExpired()
      Cleans all expired cooldowns from memory.

      Useful for periodic cleanup tasks.

    • getCooldowns

      public Map<UUID,Map<String,CooldownManager.Cooldown>> getCooldowns()
    • setCooldowns

      public void setCooldowns(Map<UUID,Map<String,CooldownManager.Cooldown>> map)
      Restores cooldowns from a saved map.

      Existing cooldowns are wiped and replaced.

      Parameters:
      map - Cooldowns previously saved.