Cleanup ability context

This commit is contained in:
Laurin
2025-12-01 19:45:49 +01:00
parent 7634694b2e
commit ac185e35ce
5 changed files with 147 additions and 73 deletions

View File

@@ -8,34 +8,59 @@ 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
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 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 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 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 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 clearAllHits(
player: Player
) {
hitCounts.remove( player.uniqueId )
}
fun clearAll() {
fun clearAll()
{
hitCounts.clear()
}
}