Class BaseCommandExecutor

java.lang.Object
com.ultikits.ultitools.abstracts.command.BaseCommandExecutor
All Implemented Interfaces:
org.bukkit.command.CommandExecutor, org.bukkit.command.TabCompleter, org.bukkit.command.TabExecutor

public abstract class BaseCommandExecutor extends Object implements org.bukkit.command.TabExecutor
Base command executor with improved architecture using Chain of Responsibility pattern. This class provides a cleaner, more extensible command handling system.

使用责任链模式改进架构的基础命令执行器。 此类提供更清晰、更可扩展的命令处理系统。

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

  • Constructor Details

    • BaseCommandExecutor

      public BaseCommandExecutor()
      Creates a new command executor with default validators. 使用默认验证器创建新的命令执行器。
    • BaseCommandExecutor

      public BaseCommandExecutor(ValidatorChain validatorChain)
      Creates a new command executor with a custom validator chain. 使用自定义验证器链创建新的命令执行器。
      Parameters:
      validatorChain - the custom validator chain
  • Method Details

    • createDefaultValidatorChain

      protected ValidatorChain createDefaultValidatorChain()
      Creates the default validator chain with standard validators. Override this method to customize the validation pipeline. 创建具有标准验证器的默认验证器链。 重写此方法以自定义验证管道。
      Returns:
      the validator chain
    • scanCommandMappings

      private void scanCommandMappings()
      Scans methods for command mappings. 扫描方法以获取命令映射。
    • handleHelp

      protected abstract void handleHelp(org.bukkit.command.CommandSender sender)
      Handles the help command. Override to provide custom help. 处理帮助命令。重写以提供自定义帮助。
      Parameters:
      sender - the command sender
    • getHelpCommand

      protected String getHelpCommand()
      Gets the help command string. 获取帮助命令字符串。
      Returns:
      the help command
    • onCommand

      public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String alias, String[] args)
      Specified by:
      onCommand in interface org.bukkit.command.CommandExecutor
    • executeCommand

      protected void executeCommand(CommandContext context, Method method, Object[] params)
      Executes the command method. Supports both synchronous and asynchronous execution via @AsyncCommand or @RunAsync. 执行命令方法。 通过 @AsyncCommand 或 @RunAsync 支持同步和异步执行。
      Parameters:
      context - the command context
      method - the method to execute
      params - the method parameters
    • matchMethod

      @Nullable protected Method matchMethod(String[] args)
      Matches arguments to a registered method. 将参数匹配到已注册的方法。
      Parameters:
      args - the command arguments
      Returns:
      the matched method, or null if not found
    • calculateMatchScore

      private int calculateMatchScore(String[] formatArgs, String[] actualArgs)
      Calculates a match score for format vs actual args. 计算格式与实际参数的匹配分数。
      Parameters:
      formatArgs - the format arguments
      actualArgs - the actual arguments
      Returns:
      the match score (-1 if no match)
    • isParameter

      private boolean isParameter(String arg)
    • parseParameters

      protected Map<String,String[]> parseParameters(String[] args, String format)
      Parses command arguments into named parameters. 将命令参数解析为命名参数。
      Parameters:
      args - the command arguments
      format - the command format
      Returns:
      map of parameter names to values
    • extractParameterName

      private String extractParameterName(String formatArg)
    • validateParameterCount

      protected boolean validateParameterCount(String[] args, String format, org.bukkit.command.CommandSender sender, org.bukkit.command.Command command)
      Validates the parameter count. 验证参数数量。
    • buildMethodParams

      @Nullable protected Object[] buildMethodParams(CommandContext context, Method method)
      Builds the method parameters from the command context. 从命令上下文构建方法参数。
      Parameters:
      context - the command context
      method - the method to invoke
      Returns:
      the method parameters, or null if parsing fails
    • resolveParameter

      private Object resolveParameter(CommandContext context, Parameter parameter)
    • isSenderType

      private static boolean isSenderType(Class<?> paramType)
    • resolveSender

      private Object resolveSender(CommandContext context, Class<?> paramType)
    • resolveCmdParam

      private Object resolveCmdParam(CommandContext context, Parameter parameter, Class<?> paramType)
    • parseParameterValue

      protected Object parseParameterValue(String[] values, Class<?> type) throws TypeParseException
      Parses a parameter value to the target type. 将参数值解析为目标类型。
      Parameters:
      values - the string values
      type - the target type
      Returns:
      the parsed value
      Throws:
      TypeParseException
    • onTabComplete

      @Nullable public List<String> onTabComplete(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String alias, String[] args)
      Specified by:
      onTabComplete in interface org.bukkit.command.TabCompleter
    • suggest

      protected List<String> suggest(org.bukkit.entity.Player player, org.bukkit.command.Command command, String[] args)
      Generates tab completion suggestions. Override this method to provide custom suggestions. 生成 Tab 补全建议。 重写此方法以提供自定义建议。
      Parameters:
      player - the player requesting completion
      command - the command
      args - the current arguments
      Returns:
      list of suggestions
    • getMappings

      public Map<String,Method> getMappings()
      Gets all registered command mappings. 获取所有已注册的命令映射。
      Returns:
      unmodifiable map of format to method
    • addValidator

      public void addValidator(CommandValidator validator)
      Adds a custom validator to the chain. 向链中添加自定义验证器。
      Parameters:
      validator - the validator to add
    • removeValidator

      public void removeValidator(CommandValidator validator)
      Removes a validator from the chain. 从链中移除验证器。
      Parameters:
      validator - the validator to remove
    • extractModuleName

      private String extractModuleName()
      Extract module name from the concrete command executor class. Uses the simple class name as a reasonable approximation.