java.lang.Object
com.winterhavenmc.library.messagebuilder.adapters.pipeline.cooldown.MessageCooldownMap
All Implemented Interfaces:
CooldownMap

public final class MessageCooldownMap extends Object implements 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 Details

    • MessageCooldownMap

      public MessageCooldownMap()
  • Method Details

    • putExpirationTime

      public void putExpirationTime(Recipient.Sendable recipient, FinalMessageRecord messageRecord)
      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.

      Specified by:
      putExpirationTime in interface CooldownMap
      Parameters:
      recipient - the message recipient
      messageRecord - the message record containing the delay configuration
    • notCooling

      public boolean notCooling(CooldownKey key)
      Checks whether the message corresponding to the given cooldown string is currently cooling down for a recipient.

      Returns true if the string has no cooldown entry or the cooldown has expired.

      Specified by:
      notCooling in interface CooldownMap
      Parameters:
      key - the composed cooldown string
      Returns:
      true if the cooldown has expired or doesn't exist
    • removeExpired

      public int removeExpired()
      Removes all expired cooldown entries from the internal map.
      Specified by:
      removeExpired in interface CooldownMap
      Returns:
      the number of entries removed