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)
Event.Result
限定符和类型 | 字段和说明 |
---|---|
protected Action |
action |
protected Block |
blockClicked |
protected BlockFace |
blockFace |
protected ItemStack |
item |
player
构造器和说明 |
---|
PlayerInteractEvent(Player who,
Action action,
ItemStack item,
Block clickedBlock,
BlockFace clickedFace) |
PlayerInteractEvent(Player who,
Action action,
ItemStack item,
Block clickedBlock,
BlockFace clickedFace,
EquipmentSlot hand) |
限定符和类型 | 方法和说明 |
---|---|
Action |
getAction()
获取本次交互的类型
原文:Returns the action type
|
BlockFace |
getBlockFace()
返回被点击的方块的朝向
Returns the face of the block that was clicked
|
Block |
getClickedBlock()
返回被点击的方块
原文:Returns the clicked block
|
EquipmentSlot |
getHand()
获取用来执行本次交互的手, 但当
Action.PHYSICAL 时可能为空
译注:也就是 getAction() 为 Action.PHYSICAL 时
The hand used to perform this interaction. |
static HandlerList |
getHandlerList() |
HandlerList |
getHandlers() |
ItemStack |
getItem()
获取本事件玩家手中的物品, 手中物品为空时会返回null
原文:Returns the item in hand represented by this event
|
Material |
getMaterial()
方便的方法, 返回由此事件表示的物品的材质
原文:Convenience method.
|
boolean |
hasBlock()
检查这个事件是否涉及到一个方块
原文:Check if this event involved a block
|
boolean |
hasItem()
检查这个事件是否涉及一个物品
原文:Check if this event involved an item
|
boolean |
isBlockInHand()
返回这个事件触发是否由放置方块所触发的
原文:Convenience method to inform the user whether this was a block
placement event.
|
boolean |
isCancelled()
获取本事件的取消状态.
|
void |
setCancelled(boolean cancel)
设置本事件的取消状态, 取消的事件不会在服务器中执行, 但仍然会传递给其他插件对本事件的监听
取消这个事件将会阻止玩家吃东西(玩家不会失去食物), 阻止弓箭/雪球/蛋发射...
|
void |
setUseInteractedBlock(Event.Result useInteractedBlock) |
void |
setUseItemInHand(Event.Result useItemInHand) |
Event.Result |
useInteractedBlock()
该方法会得到在对方块进行点击后(如果有的话)所采取的动作.
|
Event.Result |
useItemInHand()
该方法会得到玩家拿着的物品的动作.
|
getPlayer
getEventName, isAsynchronous
protected ItemStack item
protected Action action
protected Block blockClicked
protected BlockFace blockFace
public PlayerInteractEvent(Player who, Action action, ItemStack item, Block clickedBlock, BlockFace clickedFace)
public Action getAction()
原文:Returns the action type
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
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 时将会阻止本事件触发public ItemStack getItem()
原文:Returns the item in hand represented by this event
public Material getMaterial()
public boolean hasBlock()
public boolean hasItem()
public boolean isBlockInHand()
原文:Convenience method to inform the user whether this was a block placement event.
public Block getClickedBlock()
原文:Returns the clicked block
public BlockFace getBlockFace()
Returns the face of the block that was clicked
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
public void setUseInteractedBlock(Event.Result useInteractedBlock)
useInteractedBlock
- 被交互的方块进行的动作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.
public void setUseItemInHand(Event.Result useItemInHand)
useItemInHand
- 手中的物品采取的行动public EquipmentSlot getHand()
Action.PHYSICAL
时可能为空
译注:也就是 getAction()
为 Action.PHYSICAL
时
The hand used to perform this interaction. May be null in the case of
Action.PHYSICAL
.
public HandlerList getHandlers()
getHandlers
在类中 Event
public static HandlerList getHandlerList()