类 PlayerInteractEvent

所有已实现的接口:
Cancellable

public class PlayerInteractEvent extends PlayerEvent implements Cancellable
当玩家对一个对象或空气进行交互时触发本事件, 可能在左右手交互时也会被触发

你可以使用 getHand() 方法来确定是哪只手

如果是原版行为触发了本事件, 则本事件将会被取消(例如与空气进行交互)

原文:Represents an event that is called when a player interacts with an object or air, potentially fired once for each hand. The hand can be determined using getHand().

This event will fire as cancelled if the vanilla behavior is to do nothing (e.g interacting with air)

  • 字段详细资料

    • item

      protected ItemStack item
    • action

      protected Action action
    • blockClicked

      protected Block blockClicked
    • blockFace

      protected BlockFace blockFace
  • 构造器详细资料

  • 方法详细资料

    • getAction

      public Action getAction()
      获取本次交互的类型

      原文:Returns the action type

      返回:
      Action 返回交互的类型
    • isCancelled

      public boolean isCancelled()
      获取本事件的取消状态.

      原文:Gets the cancellation state of this event. Set to true if you want to prevent buckets from placing water and so forth

      指定者:
      isCancelled 在接口中 Cancellable
      返回:
      boolean 取消状态
    • setCancelled

      public void setCancelled(boolean cancel)
      设置本事件的取消状态, 取消的事件不会在服务器中执行, 但仍然会传递给其他插件对本事件的监听

      取消这个事件将会阻止玩家吃东西(玩家不会失去食物), 阻止弓箭/雪球/蛋发射...(玩家不会失去弹药)

      原文:Sets the cancellation state of this event. A canceled event will not be executed in the server, but will still pass to other plugins

      Canceling this event will prevent use of food (player won't lose the food item), prevent bows/snowballs/eggs from firing, etc. (player won't lose the ammo)

      指定者:
      setCancelled 在接口中 Cancellable
      参数:
      cancel - 设置为 true 时将会阻止本事件触发
    • getItem

      public ItemStack getItem()
      获取本事件玩家手中的物品, 手中物品为空时会返回null

      原文:Returns the item in hand represented by this event

      返回:
      ItemStack 使用的物品
    • getMaterial

      public Material getMaterial()
      方便的方法, 返回由此事件表示的物品的材质 原文:Convenience method. Returns the material of the item represented by this event
      返回:
      Material 所用物品的材质
    • hasBlock

      public boolean hasBlock()
      检查这个事件是否涉及到一个方块 原文:Check if this event involved a block
      返回:
      boolean 如果涉及到则返回true
    • hasItem

      public boolean hasItem()
      检查这个事件是否涉及一个物品 原文:Check if this event involved an item
      返回:
      boolean 如果涉及到则返回true
    • isBlockInHand

      public boolean isBlockInHand()
      返回这个事件触发是否由放置方块所触发的

      原文:Convenience method to inform the user whether this was a block placement event.

      返回:
      boolean 如果手中的物品是一个方块,则为true
    • getClickedBlock

      public Block getClickedBlock()
      返回被点击的方块

      原文:Returns the clicked block

      返回:
      Block 点击的方块
    • getBlockFace

      public BlockFace getBlockFace()
      返回被点击的方块的朝向

      Returns the face of the block that was clicked

      返回:
      BlockFace 被点击的方块的朝向
    • useInteractedBlock

      public Event.Result useInteractedBlock()
      该方法会得到在对方块进行点击后(如果有的话)所采取的动作.

      这个事件将会处理所有被点击的方块, 但是大多数的方块都没有默认的动作.

      原文:This event gets processed for all blocks, but most don't have a default action This controls the action to take with the block (if any) that was clicked on. This event gets processed for all blocks, but most don't have a default action

      返回:
      被交互的方块进行的动作
    • setUseInteractedBlock

      public void setUseInteractedBlock(Event.Result useInteractedBlock)
      参数:
      useInteractedBlock - 被交互的方块进行的动作
    • useItemInHand

      public Event.Result useItemInHand()
      该方法会得到玩家拿着的物品的动作.

      这包括方块和物品(如打火石和铁锭或唱片).

      当其动作设置为默认值,如果不采取行动的被交互的方块将被允许。

      原文:This controls the action to take with the item the player is holding. This includes both blocks and items (such as flint and steel or records). When this is set to default, it will be allowed if no action is taken on the interacted block.

      返回:
      手中的物品采取的行动
    • setUseItemInHand

      public void setUseItemInHand(Event.Result useItemInHand)
      参数:
      useItemInHand - 手中的物品采取的行动
    • getHand

      public EquipmentSlot getHand()
      获取用来执行本次交互的手, 但当 Action.PHYSICAL 时可能为空 译注:也就是 getAction()Action.PHYSICAL

      The hand used to perform this interaction. May be null in the case of Action.PHYSICAL.

      返回:
      用来交互的手, 可能为null。
    • getHandlers

      public HandlerList getHandlers()
      指定者:
      getHandlers 在类中 Event
    • getHandlerList

      public static HandlerList getHandlerList()