Interface CommandSender

All Superinterfaces:
Permissible, ServerOperator
All Known Subinterfaces:
ICommandBlock
All Known Implementing Classes:
BlockEntityCommandBlock, CapturingCommandSender, ConsoleCommandSender, ExecutorCommandSender, NPCCommandSender, Player, RemoteConsoleCommandSender

public interface CommandSender extends Permissible
能发送命令的对象.
可以是一个玩家或者一个控制台或者一个实体或者其他.

Who sends commands.
That can be a player or a console.

Since:
Nukkit 1.0 | Nukkit API 1.0.0
Author:
MagicDroidX(code) @ Nukkit Project, 粉鞋大妈(javadoc) @ Nukkit Project, smartcmd(code) @ PowerNukkitX Project
See Also:
  • Method Details

    • sendMessage

      void sendMessage(String message)
      给命令发送者返回信息.

      Sends a message to the command sender.

      Parameters:
      message - 要发送的信息.
      Message to send.
      Since:
      Nukkit 1.0 | Nukkit API 1.0.0
      See Also:
    • sendMessage

      void sendMessage(TextContainer message)
      给命令发送者返回信息.

      Sends a message to the command sender.

      Parameters:
      message - 要发送的信息.
      Message to send.
      Since:
      Nukkit 1.0 | Nukkit API 1.0.0
    • sendCommandOutput

      @PowerNukkitXOnly @Since("1.19.60-r1") void sendCommandOutput(CommandOutputContainer container)
      Send command output.
      Parameters:
      container - the container
    • getServer

      Server getServer()
      返回命令发送者所在的服务器.

      Returns the server of the command sender.

      Returns:
      命令发送者所在的服务器.
      the server of the command sender.
      Since:
      Nukkit 1.0 | Nukkit API 1.0.0
    • getName

      @NotNull String getName()
      返回命令发送者的名称.
      如果命令发送者是一个玩家,将会返回他的玩家名字(name)不是显示名字(display name).
      如果命令发送者是控制台,将会返回"CONSOLE".
      当你需要判断命令的执行者是不是控制台时,可以用这个:
      if(sender instanceof ConsoleCommandSender) .....;

      Returns the name of the command sender.
      If this command sender is a player, will return his/her player name(not display name).
      If it is a console, will return "CONSOLE".
      When you need to determine if the sender is a console, use this:
      if(sender instanceof ConsoleCommandSender) .....;

      Returns:
      命令发送者的名称.
      the name of the command sender.
      Since:
      Nukkit 1.0 | Nukkit API 1.0.0
      See Also:
    • isPlayer

      boolean isPlayer()
      Returns:
      发送者是否为玩家
      whether the sender is an player
    • isEntity

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") default boolean isEntity()
      请使用这个方法来检查发送者是否是一个实体,而不是使用代码"xxx instanceof Entity".
      因为发送者可能不是"Entity"的一个实例,但实际上它是以一个实体的身份执行命令(例如:"ExecutorCommandSender")

      please use this method to check whether the sender is an entity instead of using code "xxx instanceof Entity"
      because the sender may not an instance of "Entity" but in fact it is executing commands identity as an entity(eg: "ExecutorCommandSender")

      Returns:
      发送者是否为实体
      whether the sender is an entity
    • asEntity

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") @Nullable default Entity asEntity()
      如果发送者是一个实体,返回执行该命令的实体.

      return the entity who execute the command if the sender is a entity.

      Returns:
      实体对象
      Entity instance
    • asPlayer

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") @Nullable default Player asPlayer()
      如果发送者是一个玩家,返回执行该命令的玩家.

      return the player who execute the command if the sender is a player.

      Returns:
      玩家对象
      Player instance
    • getPosition

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") @NotNull default Position getPosition()
      Returns:
      返回发送者的Position
      return the sender's position.
    • getLocation

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") @NotNull default Location getLocation()
      Returns:
      返回发送者克隆过的Location
      return the sender's location.