Class CooldownMap
java.lang.Object
com.winterhavenmc.library.messagebuilder.pipeline.cooldown.CooldownMap
- All Implemented Interfaces:
Cooldown
An implementation of
Cooldown
that maintains a per-message cooldown map.
Each cooldown entry is keyed by a CooldownKey
, which typically includes
the UUID
of a recipient and the MessageId
of a message.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
notCooling
(CooldownKey key) Checks whether the message corresponding to the given cooldown key is currently cooling down for a recipient.void
putExpirationTime
(Recipient.Sendable recipient, FinalMessageRecord messageRecord) Registers a new cooldown expiration time for the given message and recipient.int
Removes all expired cooldown entries from the internal map.
-
Constructor Details
-
CooldownMap
public CooldownMap()
-
-
Method Details
-
putExpirationTime
Registers a new cooldown expiration time for the given message and recipient.The expiration time is determined by adding the
repeatDelay
from the message record to the current time.This method is also responsible for removing stale entries from the map, to prevent memory leakage.
- Parameters:
recipient
- the message recipientmessageRecord
- the message record containing the delay configuration
-
notCooling
Checks whether the message corresponding to the given cooldown key is currently cooling down for a recipient.Returns
true
if the key has no cooldown entry or the cooldown has expired.- Specified by:
notCooling
in interfaceCooldown
- Parameters:
key
- the composed cooldown key- Returns:
true
if the cooldown has expired or doesn't exist
-
removeExpired
public int removeExpired()Removes all expired cooldown entries from the internal map.- Returns:
- the number of entries removed
-