类 Command

java.lang.Object
org.bukkit.command.Command
直接已知子类:
BukkitCommand, FormattedCommandAlias, MultipleCommandAlias, PluginCommand

public abstract class Command extends Object
代表一个命令,在用户输入时执行各种任务.
  • 字段详细资料

  • 构造器详细资料

  • 方法详细资料

    • execute

      public abstract boolean execute(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String commandLabel, @NotNull @NotNull String[] args)
      执行命令.

      原文:Executes the command, returning its success

      参数:
      sender - 执行此命令的对象
      commandLabel - 执行命令所用的别名
      args - 传递给此命令的所有参数,用' '分割
      返回:
      如果命令执行成功则为true,false反之
    • tabComplete

      对此命令进行tab补全并返回补全项列表.

      原文:Executed on tab completion for this command, returning a list of options the player can tab through.

      参数:
      sender - 执行此命令的对象
      alias - 执行命令所用的别名
      args - 传递给此命令的所有参数,用' '分割
      返回:
      指定参数的tab补全项列表.列表永远不会为null. 列表可能是不可变的.
      抛出:
      IllegalArgumentException - 如果sender, alias, args任意一参数为null
    • tabComplete

      对此命令进行tab补全并返回补全项列表.

      原文:Executed on tab completion for this command, returning a list of options the player can tab through.

      参数:
      sender - 执行此命令的对象
      alias - 执行命令所用的别名
      args - 传递给此命令的所有参数,用' '分割
      location - 执行此命令对象所在的坐标,当无法获取命令执行者的坐标时该参数为null
      返回:
      指定参数的tab补全项列表.列表永远不会为null. 列表可能是不可变的.
      抛出:
      IllegalArgumentException - 如果参数sender, alias或args为null
    • getName

      @NotNull public @NotNull String getName()
      返回这个命令的名称.

      原文:Returns the name of this command

      返回:
      这个命令的名称
    • setName

      public boolean setName(@NotNull @NotNull String name)
      设置这个命令的名称.

      只能在注册之前使用本方法.

      如果成功设置新的名称将返回true,命令已被注册返回false.

      原文:Sets the name of this command.

      May only be used before registering the command. Will return true if the new name is set, and false if the command has already been registered.

      参数:
      name - 新的命令名称
      返回:
      如果新的名称被更改返回true,命令已被注册返回false
    • getPermission

      @Nullable public @Nullable String getPermission()
      获取用户执行此命令所需的权限.

      原文:Gets the permission required by users to be able to perform this command

      返回:
      权限名,未指定权限则为null
    • setPermission

      public void setPermission(@Nullable @Nullable String permission)
      设置用户执行此命令所需的权限.

      原文:Sets the permission required by users to be able to perform this command

      参数:
      permission - 权限名,无需任何权限则为null
    • testPermission

      public boolean testPermission(@NotNull @NotNull CommandSender target)
      测试给定的CommandSender能否执行此命令.

      如果他们没有权限,将提示他们无权执行此命令.

      原文:Tests the given CommandSender to see if they can perform this command.

      If they do not have permission, they will be informed that they cannot do this.

      参数:
      target - 要测试的用户
      返回:
      如果他们有权限则为true,false反之
    • testPermissionSilent

      public boolean testPermissionSilent(@NotNull @NotNull CommandSender target)
      测试给定的CommandSender能否执行这个命令.

      此方法不会给sender发送错误消息.

      原文:Tests the given CommandSender to see if they can perform this command.

      No error is sent to the sender.

      参数:
      target - 要测试的用户
      返回:
      他们能不能使用命令
    • getLabel

      @NotNull public @NotNull String getLabel()
      返回这个命令的别名.

      原文:Returns the label for this command

      返回:
      这个命令的别名
    • setLabel

      public boolean setLabel(@NotNull @NotNull String name)
      设置这个命令的别名.

      只能在注册之前使用本方法.

      如果成功设置新的别名将返回true,命令已被注册则返回false.

      原文:Sets the label of this command.

      May only be used before registering the command. Will return true if the new name is set, and false if the command has already been registered.

      参数:
      name - 新的命令别名
      返回:
      如果新的别名被更改返回true,命令已被注册则返回false
    • register

      public boolean register(@NotNull @NotNull CommandMap commandMap)
      把这个命令注册给一个CommandMap.

      若此命令已经注册给某个 CommandMap, 则无法再注册给别的 CommandMap, 只能修改注册过的 CommandMap.

      原文:Registers this command to a CommandMap. Once called it only allows changes the registered CommandMap

      参数:
      commandMap - 注册此命令给这个CommandMap
      返回:
      如果注册成功则为true(当前注册的CommandMap是传递的CommandMap或null),false反之
    • unregister

      public boolean unregister(@NotNull @NotNull CommandMap commandMap)
      从给定的 CommandMap 中注销此命令, 并应用所有未完成的更改.

      原文:Unregisters this command from the passed CommandMap applying any outstanding changes

      参数:
      commandMap - 指定的CommandMap
      返回:
      如果成功注销则为true(当前注册的CommandMap是传递的CommandMap或null),false反之
    • isRegistered

      public boolean isRegistered()
      返回这个命令的注册状态.

      原文:Returns the current registered state of this command

      返回:
      这个命令当前是否已注册
    • getAliases

      @NotNull public @NotNull List<String> getAliases()
      返回这个命令激活的别名列表.

      原文:Returns a list of active aliases of this command

      返回:
      别名列表
    • getPermissionMessage

      @Nullable public @Nullable String getPermissionMessage()
      返回当没有这个命令的权限时显示的消息.

      原文:Returns a message to be displayed on a failed permission check for this command

      返回:
      无权提示消息
    • getDescription

      @NotNull public @NotNull String getDescription()
      获取这个命令的简介.

      原文:Gets a brief description of this command

      返回:
      命令简介
    • getUsage

      @NotNull public @NotNull String getUsage()
      获取这个命令的用法示例.

      原文:Gets an example usage of this command

      返回:
      一个或多个用法示例
    • setAliases

      @NotNull public @NotNull Command setAliases(@NotNull @NotNull List<String> aliases)
      设置这个命令的别名. 如果别名未在 plugin.yml 中 commands 节点下的 aliases 节点定义, 则操作无效.

      原文:Sets the list of aliases to request on registration for this command. This is not effective outside of defining aliases in the PluginDescriptionFile.getCommands() (under the `aliases' node) is equivalent to this method.

      参数:
      aliases - 要为这个命令注册的别名
      返回:
      这个命令对象,可用于链式调用
    • setDescription

      @NotNull public @NotNull Command setDescription(@NotNull @NotNull String description)
      设置此命令的简介.在PluginDescriptionFile.getCommands()description 节点上定义介绍与本方法是等效的.

      原文:Sets a brief description of this command. Defining a description in the PluginDescriptionFile.getCommands() (under the `description' node) is equivalent to this method.

      参数:
      description - 新的命令介绍
      返回:
      这个命令对象,可用于链式调用
    • setPermissionMessage

      @NotNull public @NotNull Command setPermissionMessage(@Nullable @Nullable String permissionMessage)
      设置当没有这个命令的权限时发送的消息.

      原文:Sets the message sent when a permission check fails

      参数:
      permissionMessage - 新的无权提示消息,null表示默认消息,空字符串表示没有提示消息
      返回:
      这个命令对象,可用于链式调用
    • setUsage

      @NotNull public @NotNull Command setUsage(@NotNull @NotNull String usage)
      设置这个命令的用法示例.

      原文:Sets the example usage of this command

      参数:
      usage - 新的用法示例
      返回:
      命令对象
    • broadcastCommandMessage

      public static void broadcastCommandMessage(@NotNull @NotNull CommandSender source, @NotNull @NotNull String message)
    • broadcastCommandMessage

      public static void broadcastCommandMessage(@NotNull @NotNull CommandSender source, @NotNull @NotNull String message, boolean sendToSource)
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object