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

public class UsageLockValidator extends Object implements 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
  • Field Details

    • ORDER

      private static final int ORDER
      See Also:
    • senderLocks

      private final Map<UUID,Set<String>> senderLocks
      Locks per sender: player UUID -> set of locked method keys
    • serverLocks

      private final Map<String,UUID> serverLocks
      Server-wide locks: method key -> locking player UUID
  • Constructor Details

    • UsageLockValidator

      public UsageLockValidator()
  • 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
    • validateSenderLock

      private CommandValidator.ValidationResult validateSenderLock(CommandContext context, String methodKey)
    • validateServerLock

      private CommandValidator.ValidationResult validateServerLock(CommandContext context, String methodKey)
    • acquireLock

      public boolean acquireLock(CommandContext context)
      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

      public void releaseLock(CommandContext context)
      Releases a lock after command execution. Should be called after command execution completes (success or failure). 在命令执行后释放锁。 应在命令执行完成(成功或失败)后调用。
      Parameters:
      context - the command context
    • clearPlayerLocks

      public void clearPlayerLocks(UUID playerId)
      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

      public boolean isLocked(UUID playerId, String methodKey)
      Checks if a specific method is locked for a player. 检查特定方法是否对玩家锁定。
      Parameters:
      playerId - the player's UUID
      methodKey - the method key
      Returns:
      true if locked
    • 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