Class UsageLockValidator
java.lang.Object
com.ultikits.ultitools.abstracts.command.validation.validators.UsageLockValidator
- All Implemented Interfaces:
CommandValidator
Validates and manages command usage locks to prevent concurrent execution.
Supports sender-specific and server-wide locks.
验证和管理命令使用锁以防止并发执行。 支持发送者特定锁和服务器范围锁。
- 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
FieldsModifier and TypeFieldDescriptionprivate static final intLocks per sender: player UUID -> set of locked method keysServer-wide locks: method key -> locking player UUID -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanacquireLock(CommandContext context) Acquires a lock for command execution.voidClears all locks.voidclearPlayerLocks(UUID playerId) Clears all locks for a player.getName()Gets the name of this validator for debugging and logging purposes.intgetOrder()Gets the order of this validator.booleanChecks if a specific method is locked for a player.voidreleaseLock(CommandContext context) Releases a lock after command execution.validate(CommandContext context) Validates the command context.validateSenderLock(CommandContext context, String methodKey) validateServerLock(CommandContext context, String methodKey) 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:
-
senderLocks
Locks per sender: player UUID -> set of locked method keys -
serverLocks
Server-wide locks: method key -> locking player UUID
-
-
Constructor Details
-
UsageLockValidator
public UsageLockValidator()
-
-
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
-
validateSenderLock
private CommandValidator.ValidationResult validateSenderLock(CommandContext context, String methodKey) -
validateServerLock
private CommandValidator.ValidationResult validateServerLock(CommandContext context, String methodKey) -
acquireLock
Acquires a lock for command execution. Should be called before executing the command. 获取命令执行的锁。 应在执行命令之前调用。- Parameters:
context- the command context- Returns:
- true if lock was acquired, false if already locked
-
releaseLock
Releases a lock after command execution. Should be called after command execution completes (success or failure). 在命令执行后释放锁。 应在命令执行完成(成功或失败)后调用。- Parameters:
context- the command context
-
clearPlayerLocks
Clears all locks for a player. Useful when a player disconnects. 清除玩家的所有锁。 当玩家断开连接时很有用。- Parameters:
playerId- the player's UUID
-
clearAllLocks
public void clearAllLocks()Clears all locks. 清除所有锁。 -
isLocked
Checks if a specific method is locked for a player. 检查特定方法是否对玩家锁定。- Parameters:
playerId- the player's UUIDmethodKey- the method key- Returns:
- true if locked
-
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
-