Added AbilityHitListener.kt

This commit is contained in:
Laurin
2025-12-01 19:35:33 +01:00
committed by GitHub
parent e9bb8f9a90
commit 7634694b2e
5 changed files with 203 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package club.mcscrims.speedhg.ability
import org.bukkit.entity.Player
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
class CooldownManager {
private val cooldowns = ConcurrentHashMap<UUID, ConcurrentHashMap<String, Long>>()
fun startCooldown(player: Player, key: String, seconds: Int) {
val expiryTime = System.currentTimeMillis() + (seconds * 1000L)
cooldowns.computeIfAbsent(player.uniqueId) { ConcurrentHashMap() }[key] = expiryTime
}
fun isOnCooldown(player: Player, key: String): Boolean {
val playerCooldowns = cooldowns[player.uniqueId] ?: return false
val expiryTime = playerCooldowns[key] ?: return false
if (System.currentTimeMillis() >= expiryTime) {
playerCooldowns.remove(key)
if (playerCooldowns.isEmpty()) {
cooldowns.remove(player.uniqueId)
}
return false
}
return true
}
fun getRemainingSeconds(player: Player, key: String): Double {
val playerCooldowns = cooldowns[player.uniqueId] ?: return 0.0
val expiryTime = playerCooldowns[key] ?: return 0.0
val remaining = (expiryTime - System.currentTimeMillis()) / 1000.0
return if (remaining > 0) remaining else 0.0
}
fun clearCooldown(player: Player, key: String) {
cooldowns[player.uniqueId]?.remove(key)
}
fun clearAllCooldowns(player: Player) {
cooldowns.remove(player.uniqueId)
}
fun clearAll() {
cooldowns.clear()
}
}