PlayerAttackCooldownTracker

public final class PlayerAttackCooldownTracker

Tracks each player's last melee-hit tick so the combat pipeline can derive melee attack charge from the real-time gap between primary swings.

This is used by the player→elite damage formula instead of Bukkit's Player.getAttackCooldown() value, which can be observed after the swing has already consumed/reset the vanilla cooldown. The captured tick gap still lets debug output distinguish properly paced swings from fast clicking.

Design

  • One ConcurrentHashMap keyed by player UUID, valued by the game tick of their last hit. O(1) read/write per hit.
  • Lazy initialization. The eviction sweep is only registered the first time recordHit is called — the tracker imposes zero cost on servers where no one is fighting.
  • Bounded memory. A GameClock-scheduled sweep evicts UUIDs idle for more than IDLE_EVICTION_TICKS, so a player who logs out and never returns does not leak.
  • No quit-listener dependency. The sweep handles cleanup, mirroring the existing pattern used by com.magmaguy.elitemobs.combatsystem.antiexploit.AutoclickerThrottle.

Properties

Link copied to clipboard
public final static long IDLE_EVICTION_TICKS
Idle threshold before a UUID is evicted: 5 minutes of game ticks.
Link copied to clipboard
public final static long NO_PREVIOUS_HIT
Sentinel returned when no previous hit is on file for the player.
Link copied to clipboard
public final static long SWEEP_INTERVAL_TICKS
Sweep interval: every 5 minutes (20 ticks/sec × 60 sec × 5 min = 6000 ticks).

Functions

Link copied to clipboard
public static void clearAll()
Drops all tracked entries.
Link copied to clipboard
public static void forget(UUID uuid)
Forgets a player's last-hit tick.
Link copied to clipboard
public static long recordHit(Player player)
Records a melee hit from the given player and returns the number of game ticks elapsed since their previously tracked hit, or NO_PREVIOUS_HIT when this is their first recorded hit since plugin start (or since their last eviction).
Link copied to clipboard
public static void shutdown()
Cancels the eviction sweep and clears tracked state.