Cancellable
public class PlayerInteractEvent extends PlayerEvent implements Cancellable
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.
Event.Result
Modifier and Type | Field | Description |
---|---|---|
protected Action |
action |
|
protected Block |
blockClicked |
|
protected BlockFace |
blockFace |
|
protected ItemStack |
item |
player
Constructor | Description |
---|---|
PlayerInteractEvent(Player who,
Action action,
ItemStack item,
Block clickedBlock,
BlockFace clickedFace) |
|
PlayerInteractEvent(Player who,
Action action,
ItemStack item,
Block clickedBlock,
BlockFace clickedFace,
EquipmentSlot hand) |
Modifier and Type | Method | Description |
---|---|---|
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() |
The hand used to perform this interaction.
|
static HandlerList |
getHandlerList() |
|
HandlerList |
getHandlers() |
|
ItemStack |
getItem() |
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() |
Deprecated.
This event has two possible cancellation states, one for
useInteractedBlock() and one for useItemInHand() . 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. |
void |
setCancelled(boolean cancel) |
Sets the cancellation state of this event.
|
void |
setUseInteractedBlock(Event.Result useInteractedBlock) |
|
void |
setUseItemInHand(Event.Result useItemInHand) |
|
Event.Result |
useInteractedBlock() |
This controls the action to take with the block (if any) that was
clicked on.
|
Event.Result |
useItemInHand() |
This controls the action to take with the item the player is holding.
|
getEventName, isAsynchronous
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getPlayer
protected ItemStack item
protected Action action
protected Block blockClicked
protected BlockFace blockFace
public PlayerInteractEvent(@NotNull Player who, @NotNull Action action, @Nullable ItemStack item, @Nullable Block clickedBlock, @NotNull BlockFace clickedFace)
@NotNull public Action getAction()
@Deprecated public boolean isCancelled()
useInteractedBlock()
and one for useItemInHand()
. 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.isCancelled
in interface Cancellable
public void setCancelled(boolean cancel)
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
in interface Cancellable
cancel
- true if you wish to cancel this event@Nullable public ItemStack getItem()
@NotNull public Material getMaterial()
public boolean hasBlock()
public boolean hasItem()
public boolean isBlockInHand()
@Nullable public Block getClickedBlock()
@NotNull public BlockFace getBlockFace()
@NotNull public Event.Result useInteractedBlock()
public void setUseInteractedBlock(@NotNull Event.Result useInteractedBlock)
useInteractedBlock
- the action to take with the interacted block@NotNull public Event.Result useItemInHand()
public void setUseItemInHand(@NotNull Event.Result useItemInHand)
useItemInHand
- the action to take with the item in hand@Nullable public EquipmentSlot getHand()
Action.PHYSICAL
.@NotNull public HandlerList getHandlers()
getHandlers
in class Event
@NotNull public static HandlerList getHandlerList()
Copyright © 2020. All rights reserved.