Class MessageCooldownMap
java.lang.Object
com.winterhavenmc.library.messagebuilder.adapters.pipeline.cooldown.MessageCooldownMap
- All Implemented Interfaces:
CooldownMap
An implementation of
CooldownMap 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 TypeMethodDescriptionbooleannotCooling(CooldownKey key) Checks whether the message corresponding to the given cooldown string is currently cooling down for a recipient.voidputExpirationTime(Recipient.Sendable recipient, FinalMessageRecord messageRecord) Registers a new cooldown expiration time for the given message and recipient.intRemoves all expired cooldown entries from the internal map.
-
Constructor Details
-
MessageCooldownMap
public MessageCooldownMap()
-
-
Method Details
-
putExpirationTime
Registers a new cooldown expiration time for the given message and recipient.The expiration time is determined by adding the
repeatDelayfrom the message record to the current time.This method is also responsible for removing stale entries from the map, to prevent memory leakage.
- Specified by:
putExpirationTimein interfaceCooldownMap- Parameters:
recipient- the message recipientmessageRecord- the message record containing the delay configuration
-
notCooling
Checks whether the message corresponding to the given cooldown string is currently cooling down for a recipient.Returns
trueif the string has no cooldown entry or the cooldown has expired.- Specified by:
notCoolingin interfaceCooldownMap- Parameters:
key- the composed cooldown string- Returns:
trueif the cooldown has expired or doesn't exist
-
removeExpired
public int removeExpired()Removes all expired cooldown entries from the internal map.- Specified by:
removeExpiredin interfaceCooldownMap- Returns:
- the number of entries removed
-