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(@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) |
Modifier and Type | Method | Description |
---|---|---|
@NotNull Action |
getAction() |
Returns the action type
|
@NotNull BlockFace |
getBlockFace() |
Returns the face of the block that was clicked
|
@Nullable Block |
getClickedBlock() |
Returns the clicked block
|
@Nullable EquipmentSlot |
getHand() |
The hand used to perform this interaction.
|
static @NotNull HandlerList |
getHandlerList() |
|
@NotNull HandlerList |
getHandlers() |
|
@Nullable ItemStack |
getItem() |
Returns the item in hand represented by this event
|
@NotNull 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() . |
void |
setCancelled(boolean cancel) |
Sets the cancellation state of this event.
|
void |
setUseInteractedBlock(@NotNull Event.Result useInteractedBlock) |
|
void |
setUseItemInHand(@NotNull Event.Result useItemInHand) |
|
@NotNull Event.Result |
useInteractedBlock() |
This controls the action to take with the block (if any) that was
clicked on.
|
@NotNull Event.Result |
useItemInHand() |
This controls the action to take with the item the player is holding.
|
callEvent, 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 @NotNull Player who, @NotNull @NotNull Action action, @Nullable @Nullable ItemStack item, @Nullable @Nullable Block clickedBlock, @NotNull @NotNull BlockFace clickedFace)
@NotNull public @NotNull 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 @Nullable ItemStack getItem()
@NotNull public @NotNull Material getMaterial()
public boolean hasBlock()
public boolean hasItem()
public boolean isBlockInHand()
@Nullable public @Nullable Block getClickedBlock()
@NotNull public @NotNull BlockFace getBlockFace()
@NotNull public @NotNull Event.Result useInteractedBlock()
public void setUseInteractedBlock(@NotNull @NotNull Event.Result useInteractedBlock)
useInteractedBlock
- the action to take with the interacted block@NotNull public @NotNull Event.Result useItemInHand()
public void setUseItemInHand(@NotNull @NotNull Event.Result useItemInHand)
useItemInHand
- the action to take with the item in hand@Nullable public @Nullable EquipmentSlot getHand()
Action.PHYSICAL
.@NotNull public @NotNull HandlerList getHandlers()
getHandlers
in class Event
@NotNull public static @NotNull HandlerList getHandlerList()
Copyright © 2020. All rights reserved.