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

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

    • CooldownMap

      public CooldownMap()
  • 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.

      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 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 interface Cooldown
      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