类 PlayerInteractEvent
- 所有已实现的接口:
Cancellable
无论玩家使用的是左手还是右手, 都有可能分别触发本事件. 你可以使用 getHand()
方法来确定玩家使用的是哪只手.
如果是原版行为触发了本事件, 则本事件将会被取消(例如与空气进行交互).
For the purpose of avoiding doubt, this means
that the event will only be in the cancelled state if it is fired as a result
of some prediction made by the server where no subsequent code will run,
rather than when the subsequent interaction activity (e.g. placing a block in
an illegal position (BlockCanBuildEvent
) will fail.
原文: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). For the purpose of avoiding doubt, this means
that the event will only be in the cancelled state if it is fired as a result
of some prediction made by the server where no subsequent code will run,
rather than when the subsequent interaction activity (e.g. placing a block in
an illegal position (BlockCanBuildEvent
) will fail.
-
嵌套类概要
从类继承的嵌套类/接口 org.bukkit.event.Event
Event.Result
-
字段概要
从类继承的字段 org.bukkit.event.player.PlayerEvent
player
-
构造器概要
构造器说明PlayerInteractEvent
(@NotNull Player who, @NotNull Action action, @Nullable ItemStack item, @Nullable Block clickedBlock, @NotNull BlockFace clickedFace) PlayerInteractEvent
(@NotNull Player who, @NotNull Action action, @Nullable ItemStack item, @Nullable Block clickedBlock, @NotNull BlockFace clickedFace, @Nullable EquipmentSlot hand) PlayerInteractEvent
(@NotNull Player who, @NotNull Action action, @Nullable ItemStack item, @Nullable Block clickedBlock, @NotNull BlockFace clickedFace, @Nullable EquipmentSlot hand, @Nullable Vector clickedPosition) -
方法概要
修饰符和类型方法说明获取本次交互的动作类型.返回被点击的方块的朝向.返回被点击的方块.Gets the exact position on the block the player interacted with, this will be null outside ofAction.RIGHT_CLICK_BLOCK
.getHand()
获取用来进行本次交互的手, 但当玩家的交互动作类型为Action.PHYSICAL
时可能为空.static @NotNull HandlerList
getItem()
获取玩家手中的物品, 手中未拿物品时会返回null.返回玩家所用物品的材质 (相当于getItem()后再getMateria(),但更简便一些).boolean
hasBlock()
检查交互事件是否涉及方块(与方块交互、放置方块等).boolean
hasItem()
检查玩家交互时是否手拿物品或与物品交互/交互是否涉及到物品.boolean
判断本次交互事件是否为方块放置事件 (由玩家放置方块引起的交互事件).boolean
已过时。void
setCancelled
(boolean cancel) 取消这个事件.void
setUseInteractedBlock
(@NotNull Event.Result useInteractedBlock) void
setUseItemInHand
(@NotNull Event.Result useItemInHand) 获取(控制见对应set方法)对被交互的方块采取的动作(如果有).获取(控制见下一个方法)对玩家手持的物品采取的动作/行动.从类继承的方法 org.bukkit.event.player.PlayerEvent
getPlayer
从类继承的方法 org.bukkit.event.Event
getEventName, isAsynchronous
-
字段详细资料
-
item
-
action
-
blockClicked
-
blockFace
-
-
构造器详细资料
-
PlayerInteractEvent
-
PlayerInteractEvent
-
PlayerInteractEvent
-
-
方法详细资料
-
getAction
获取本次交互的动作类型.原文:Returns the action type
- 返回:
- Action 返回交互的动作类型
-
isCancelled
已过时。This event has two possible cancellation states, one foruseInteractedBlock()
and one foruseItemInHand()
. It is possible a call might have the former false, but the latter true, eg in the case of using a firework whilst gliding. Callers should check the relevant methods individually.获取这个事件是否被取消. 如果你想防止通过水桶放水等操作, 则可以取消这个事件.原文: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
获取玩家手中的物品, 手中未拿物品时会返回null.原文:Returns the item in hand represented by this event
- 返回:
- ItemStack 使用的物品
-
getMaterial
返回玩家所用物品的材质 (相当于getItem()后再getMateria(),但更简便一些).原文: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
返回被点击的方块.原文:Returns the clicked block
- 返回:
- Block 被点击的方块
-
getBlockFace
返回被点击的方块的朝向.Returns the face of the block that was clicked
- 返回:
- BlockFace 被点击的方块的朝向
-
useInteractedBlock
获取(控制见对应set方法)对被交互的方块采取的动作(如果有). 任意方块都能触发本事件, 不过大部分情况下都没有默认动作.原文: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
- 参数:
useInteractedBlock
- 对被交互的方块采取的动作
-
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.
- 返回:
- 对玩家手持的物品采取的动作(the action to take with the item in hand)
-
setUseItemInHand
- 参数:
useItemInHand
- 对玩家手持的物品采取的动作(the action to take with the item in hand)
-
getHand
获取用来进行本次交互的手, 但当玩家的交互动作类型为Action.PHYSICAL
时可能为空.原文:The hand used to perform this interaction. May be null in the case of
Action.PHYSICAL
.- 返回:
- 用来交互的手, 可能为null
-
getClickedPosition
Gets the exact position on the block the player interacted with, this will be null outside ofAction.RIGHT_CLICK_BLOCK
.All vector components are between 0.0 and 1.0 inclusive.
- 返回:
- the clicked position. May be null.
-
getHandlers
- 指定者:
getHandlers
在类中Event
-
getHandlerList
-
useInteractedBlock()
and one foruseItemInHand()
.