org.bukkit.command.Command.execute()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(209)

本文整理了Java中org.bukkit.command.Command.execute()方法的一些代码示例,展示了Command.execute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Command.execute()方法的具体详情如下:
包路径:org.bukkit.command.Command
类名称:Command
方法名:execute

Command.execute介绍

[英]Executes the command, returning its success
[中]执行命令,返回其成功

代码示例

代码示例来源:origin: Bukkit/Bukkit

@Override
  public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    boolean result = false;

    for (Command command : commands) {
      result |= command.execute(sender, commandLabel, args);
    }

    return result;
  }
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * {@inheritDoc}
 */
public boolean dispatch(CommandSender sender, String commandLine) throws CommandException {
  String[] args = PATTERN_ON_SPACE.split(commandLine);
  if (args.length == 0) {
    return false;
  }
  String sentCommandLabel = args[0].toLowerCase();
  Command target = getCommand(sentCommandLabel);
  if (target == null) {
    return false;
  }
  try {
    // Note: we don't return the result of target.execute as thats success / failure, we return handled (true) or not handled (false)
    target.execute(sender, sentCommandLabel, Arrays_copyOfRange(args, 1, args.length));
  } catch (CommandException ex) {
    throw ex;
  } catch (Throwable ex) {
    throw new CommandException("Unhandled exception executing '" + commandLine + "' in " + target, ex);
  }
  // return true as command was handled
  return true;
}

代码示例来源:origin: SpigotMC/Spigot-API

@Override
  public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    boolean result = false;

    for (Command command : commands) {
      result |= command.execute(sender, commandLabel, args);
    }

    return result;
  }
}

代码示例来源:origin: seeseemelk/MockBukkit

@Override
public boolean dispatchCommand(CommandSender sender, String commandLine) throws CommandException
{
  assertMainThread();
  String[] commands = commandLine.split(" ");
  String commandLabel = commands[0];
  String[] args = Arrays.copyOfRange(commands, 1, commands.length);
  Command command = getPluginCommand(commandLabel);
  if (command != null)
    return command.execute(sender, commandLabel, args);
  else
    return false;
}

代码示例来源:origin: seeseemelk/MockBukkit

/**
 * Executes a command.
 * 
 * @param command The command to execute.
 * @param sender The person that executed the command.
 * @param args The arguments to pass to the commands.
 * @return The value returned by {@link Command#execute}.
 */
public CommandResult execute(Command command, CommandSender sender, String... args)
{
  assertMainThread();
  if (!(sender instanceof MessageTarget))
  {
    throw new IllegalArgumentException("Only a MessageTarget can be the sender of the command");
  }
  
  boolean status = command.execute(sender, command.getName(), args);
  CommandResult result = new CommandResult(status, (MessageTarget) sender);
  return result;
}

代码示例来源:origin: SpigotMC/Spigot-API

/**
 * {@inheritDoc}
 */
public boolean dispatch(CommandSender sender, String commandLine) throws CommandException {
  String[] args = PATTERN_ON_SPACE.split(commandLine);
  if (args.length == 0) {
    return false;
  }
  String sentCommandLabel = args[0].toLowerCase();
  Command target = getCommand(sentCommandLabel);
  if (target == null) {
    return false;
  }
  try {
    target.timings.startTiming(); // Spigot
    // Note: we don't return the result of target.execute as thats success / failure, we return handled (true) or not handled (false)
    target.execute(sender, sentCommandLabel, Arrays_copyOfRange(args, 1, args.length));
    target.timings.stopTiming(); // Spigot
  } catch (CommandException ex) {
    target.timings.stopTiming(); // Spigot
    throw ex;
  } catch (Throwable ex) {
    target.timings.stopTiming(); // Spigot
    throw new CommandException("Unhandled exception executing '" + commandLine + "' in " + target, ex);
  }
  // return true as command was handled
  return true;
}

相关文章