Class CooldownValidator
java.lang.Object
com.ultikits.ultitools.abstracts.command.validation.validators.CooldownValidator
- All Implemented Interfaces:
CommandValidator
Validates and manages command cooldowns for players.
Thread-safe implementation using ConcurrentHashMap.
验证和管理玩家的命令冷却。 使用 ConcurrentHashMap 的线程安全实现。
- Since:
- 6.2.0
- Version:
- 2.0.0
- Author:
- wisdomme
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.ultikits.ultitools.abstracts.command.validation.CommandValidator
CommandValidator.ValidationResult -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a cooldown validator with no default cooldown.CooldownValidator(int defaultCooldownSeconds) Creates a cooldown validator with a default cooldown. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyCooldown(CommandContext context) Applies cooldown after command execution.voidCleans up expired cooldowns to prevent memory leaks.voidclearCooldown(UUID playerId, String methodKey) Clears a specific cooldown for a player.voidclearCooldowns(UUID playerId) Clears all cooldowns for a player.private intgetCooldownSeconds(Method method) getName()Gets the name of this validator for debugging and logging purposes.intgetOrder()Gets the order of this validator.longgetRemainingCooldown(UUID playerId, String methodKey) Gets the remaining cooldown time in seconds.validate(CommandContext context) Validates the command context.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.ultikits.ultitools.abstracts.command.validation.CommandValidator
shouldValidate
-
Field Details
-
ORDER
private static final int ORDER- See Also:
-
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:CommandValidatorValidates the command context. 验证命令上下文。- Specified by:
validatein interfaceCommandValidator- Parameters:
context- the command context to validate- Returns:
- the validation result
-
applyCooldown
Applies cooldown after command execution. Should be called after successful command execution. 在命令执行后应用冷却。 应在成功执行命令后调用。- Parameters:
context- the command context
-
clearCooldowns
Clears all cooldowns for a player. 清除玩家的所有冷却。- Parameters:
playerId- the player's UUID
-
clearCooldown
Clears a specific cooldown for a player. 清除玩家的特定冷却。- Parameters:
playerId- the player's UUIDmethodKey- the method key
-
getRemainingCooldown
Gets the remaining cooldown time in seconds. 获取剩余的冷却时间(秒)。- Parameters:
playerId- the player's UUIDmethodKey- 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
-
getOrder
public int getOrder()Description copied from interface:CommandValidatorGets the order of this validator. Lower values are executed first. 获取此验证器的顺序。较低的值优先执行。- Specified by:
getOrderin interfaceCommandValidator- Returns:
- the order value
-
getName
Description copied from interface:CommandValidatorGets the name of this validator for debugging and logging purposes. 获取此验证器的名称,用于调试和日志记录。- Specified by:
getNamein interfaceCommandValidator- Returns:
- the validator name
-