Cleanup ability context
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user