java.lang.Object
com.ultikits.ultitools.abstracts.command.validation.validators.CooldownValidator
All Implemented Interfaces:
CommandValidator

public class CooldownValidator extends Object implements CommandValidator
Validates and manages command cooldowns for players. Thread-safe implementation using ConcurrentHashMap.

验证和管理玩家的命令冷却。 使用 ConcurrentHashMap 的线程安全实现。

Since:
6.2.0
Version:
2.0.0
Author:
wisdomme
  • Field Details

    • ORDER

      private static final int ORDER
      See Also:
    • cooldowns

      private final Map<UUID,Map<String,Long>> cooldowns
      Map of player UUID -> (method name -> cooldown end timestamp)
    • defaultCooldownSeconds

      private final int defaultCooldownSeconds
  • Constructor Details

    • CooldownValidator

      public CooldownValidator()
      Creates a cooldown validator with no default cooldown. 创建一个没有默认冷却的冷却验证器。
    • CooldownValidator

      public CooldownValidator(int defaultCooldownSeconds)
      Creates a cooldown validator with a default cooldown. 创建具有默认冷却的冷却验证器。
      Parameters:
      defaultCooldownSeconds - the default cooldown in seconds
  • Method Details

    • validate

      Description copied from interface: CommandValidator
      Validates the command context. 验证命令上下文。
      Specified by:
      validate in interface CommandValidator
      Parameters:
      context - the command context to validate
      Returns:
      the validation result
    • applyCooldown

      public void applyCooldown(CommandContext context)
      Applies cooldown after command execution. Should be called after successful command execution. 在命令执行后应用冷却。 应在成功执行命令后调用。
      Parameters:
      context - the command context
    • clearCooldowns

      public void clearCooldowns(UUID playerId)
      Clears all cooldowns for a player. 清除玩家的所有冷却。
      Parameters:
      playerId - the player's UUID
    • clearCooldown

      public void clearCooldown(UUID playerId, String methodKey)
      Clears a specific cooldown for a player. 清除玩家的特定冷却。
      Parameters:
      playerId - the player's UUID
      methodKey - the method key
    • getRemainingCooldown

      public long getRemainingCooldown(UUID playerId, String methodKey)
      Gets the remaining cooldown time in seconds. 获取剩余的冷却时间(秒)。
      Parameters:
      playerId - the player's UUID
      methodKey - the method key
      Returns:
      remaining seconds, or 0 if not on cooldown
    • cleanupExpired

      public void cleanupExpired()
      Cleans up expired cooldowns to prevent memory leaks. Should be called periodically. 清理过期的冷却以防止内存泄漏。 应定期调用。
    • getCooldownSeconds

      private int getCooldownSeconds(Method method)
    • getOrder

      public int getOrder()
      Description copied from interface: CommandValidator
      Gets the order of this validator. Lower values are executed first. 获取此验证器的顺序。较低的值优先执行。
      Specified by:
      getOrder in interface CommandValidator
      Returns:
      the order value
    • getName

      public String getName()
      Description copied from interface: CommandValidator
      Gets the name of this validator for debugging and logging purposes. 获取此验证器的名称,用于调试和日志记录。
      Specified by:
      getName in interface CommandValidator
      Returns:
      the validator name