Interface CommandExecutor

All Known Subinterfaces:
Plugin
All Known Implementing Classes:
CommonJSPlugin, PluginBase, PowerNukkitPlugin

public interface CommandExecutor
能监听命令执行的类实现的接口。
An interface what can be implemented by classes which listens command executing.
Since:
Nukkit 1.0 | Nukkit API 1.0.0
Author:
MagicDroidX(code) @ Nukkit Project, 粉鞋大妈(javadoc) @ Nukkit Project
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    onCommand(CommandSender sender, Command command, String label, String[] args)
    在命令执行时会调用的方法。
    Called when a command is executed.
  • Method Details

    • onCommand

      boolean onCommand(CommandSender sender, Command command, String label, String[] args)
      在命令执行时会调用的方法。
      Called when a command is executed.

      一个命令可以是/a_LABEL an_arg1 AN_ARG2...的形式,这时label变量的值为"a_label"args数组的元素有"an_arg1","AN_ARG2",...。注意到label变量会被转化成小写, 而args数组内字符串元素的大小写不变。
      A command can be such a form like /a_LABEL an_arg1 AN_ARG2.... At this time, the value of variable label is "a_label", and the values of elements of array args are "an_arg1","AN_ARG2",.... Notice that the value of variable label will be converted to lower case, but the cases of elements of array args won't change.

      关于返回值,如果返回false,Nukkit会给sender发送这个命令的使用方法等信息,来表示这个命令没有使用成功。 如果你的命令成功的发挥了作用,你应该返回true来表示这个命令已执行成功。
      If this function returns false, Nukkit will send command usages to command sender, to explain that the command didn't work normally. If your command works properly, a true should be returned to explain that the command works.

      如果你想测试一个命令发送者是否有权限执行这个命令, 可以使用Command.testPermissionSilent(cn.nukkit.command.CommandSender)
      If you want to test whether a command sender has the permission to execute a command, you can use Command.testPermissionSilent(cn.nukkit.command.CommandSender).

      Parameters:
      sender - 这个命令的发送者,可以是玩家或控制台等。
      The sender of this command, this can be a player or a console.
      command - 要被发送的命令。
      The command to send.
      label - 这个命令的标签。
      Label of the command.
      args - 这个命令的参数列表。
      Arguments of this command.
      Returns:
      这个命令执行是否执行成功。
      whether this command is executed successfully.
      Since:
      Nukkit 1.0 | Nukkit API 1.0.0