Class CooldownManager

java.lang.Object
dev.oumaimaa.data.CooldownManager

public final class CooldownManager extends Object
Manages player cooldowns for advertisement broadcasts. Cooldowns are persisted via DatabaseManager. Optimized to minimize autoboxing.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs the CooldownManager.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyCooldown(@NotNull org.bukkit.entity.Player player)
    Applies the cooldown to the player, storing it in memory and scheduling a save to the database.
    @NotNull String
    formatTime(long seconds)
    Formats remaining seconds into a readable string (e.g., "5m 30s").
    long
    getEffectiveCooldownSeconds(org.bukkit.entity.Player player)
    Finds the shortest cooldown duration in seconds applicable to the player based on their permissions.
    long
    getRemainingCooldown(@NotNull org.bukkit.entity.Player player)
    Checks if a player is currently on cooldown.
    void
    Saves all currently tracked cooldowns to the database (used on plugin shutdown).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CooldownManager

      public CooldownManager(@NotNull @NotNull KawaiiAdPlugin plugin)
      Constructs the CooldownManager.
      Parameters:
      plugin - The main plugin instance.
  • Method Details

    • getEffectiveCooldownSeconds

      public long getEffectiveCooldownSeconds(org.bukkit.entity.Player player)
      Finds the shortest cooldown duration in seconds applicable to the player based on their permissions.
      Parameters:
      player - The player to check.
      Returns:
      The lowest cooldown time in seconds.
    • getRemainingCooldown

      public long getRemainingCooldown(@NotNull @NotNull org.bukkit.entity.Player player)
      Checks if a player is currently on cooldown. Loads the data from the DB if necessary.
      Parameters:
      player - The player to check.
      Returns:
      The remaining time in seconds, or 0 if no cooldown applies.
    • applyCooldown

      public void applyCooldown(@NotNull @NotNull org.bukkit.entity.Player player)
      Applies the cooldown to the player, storing it in memory and scheduling a save to the database.
      Parameters:
      player - The player to apply the cooldown to.
    • saveAllCooldownsAsync

      public void saveAllCooldownsAsync()
      Saves all currently tracked cooldowns to the database (used on plugin shutdown).
    • formatTime

      @NotNull public @NotNull String formatTime(long seconds)
      Formats remaining seconds into a readable string (e.g., "5m 30s").
      Parameters:
      seconds - The total number of seconds remaining.
      Returns:
      A formatted time string.