Added AbilityHitListener.kt
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user