Package dev.oumaimaa.data
Class CooldownManager
java.lang.Object
dev.oumaimaa.data.CooldownManager
Manages player cooldowns for advertisement broadcasts.
Cooldowns are persisted via DatabaseManager. Optimized to minimize autoboxing.
-
Constructor Summary
ConstructorsConstructorDescriptionCooldownManager(@NotNull KawaiiAdPlugin plugin) Constructs the CooldownManager. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyCooldown(@NotNull org.bukkit.entity.Player player) Applies the cooldown to the player, storing it in memory and scheduling a save to the database.@NotNull StringformatTime(long seconds) Formats remaining seconds into a readable string (e.g., "5m 30s").longgetEffectiveCooldownSeconds(org.bukkit.entity.Player player) Finds the shortest cooldown duration in seconds applicable to the player based on their permissions.longgetRemainingCooldown(@NotNull org.bukkit.entity.Player player) Checks if a player is currently on cooldown.voidSaves all currently tracked cooldowns to the database (used on plugin shutdown).
-
Constructor Details
-
CooldownManager
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
Formats remaining seconds into a readable string (e.g., "5m 30s").- Parameters:
seconds- The total number of seconds remaining.- Returns:
- A formatted time string.
-