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,41 @@
package club.mcscrims.speedhg.ability
import org.bukkit.entity.Player
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
class HitCounterManager {
private val hitCounts = ConcurrentHashMap<UUID, ConcurrentHashMap<String, Int>>()
fun incrementHit(player: Player, key: String): Int {
val playerHits = hitCounts.computeIfAbsent(player.uniqueId) { ConcurrentHashMap() }
val newCount = playerHits.compute(key) { _, current -> (current ?: 0) + 1 } ?: 1
return newCount
}
fun getHits(player: Player, key: String): Int {
return hitCounts[player.uniqueId]?.get(key) ?: 0
}
fun resetHits(player: Player, key: String) {
hitCounts[player.uniqueId]?.remove(key)
}
fun hasReachedThreshold(player: Player, key: String, requiredHits: Int): Boolean {
return getHits(player, key) >= requiredHits
}
fun getRemainingHits(player: Player, key: String, requiredHits: Int): Int {
val current = getHits(player, key)
return maxOf(0, requiredHits - current)
}
fun clearAllHits(player: Player) {
hitCounts.remove(player.uniqueId)
}
fun clearAll() {
hitCounts.clear()
}
}