Package org.bukkit.event.player

# Class PlayerInteractEvent

java.lang.Object
org.bukkit.event.Event
org.bukkit.event.player.PlayerEvent
org.bukkit.event.player.PlayerInteractEvent

All Implemented Interfaces:
  `Cancellable`

public class PlayerInteractEvent extends PlayerEvent implements Cancellable
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.

## Nested Class Summary

## Nested classes/interfaces inherited from class org.bukkit.event.Event

`Event.Result`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected Action`
`action`
`protected Block`
`blockClicked`
`protected BlockFace`
`blockFace`
`protected ItemStack`
`item`

### Fields inherited from class org.bukkit.event.player.PlayerEvent

`player`

## Constructor Summary

Constructors
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)`
`PlayerInteractEvent(@NotNull Player who, @NotNull Action action, @Nullable ItemStack item, @Nullable Block clickedBlock, @NotNull BlockFace clickedFace, @Nullable EquipmentSlot hand, @Nullable Location interactionPoint)`

## Method Summary

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 Location`
`getInteractionPoint()`
The exact point at which the interaction occurred.
`@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.

### Methods inherited from class org.bukkit.event.player.PlayerEvent

`getPlayer`

### Methods inherited from class org.bukkit.event.Event

`callEvent, getEventName, isAsynchronous`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### item

protected ItemStack item

### action

protected Action action

### blockClicked

protected Block blockClicked

### blockFace

protected BlockFace blockFace

## Constructor Details

### PlayerInteractEvent

public PlayerInteractEvent(@NotNull @NotNull Player who, @NotNull @NotNull Action action, @Nullable @Nullable ItemStack item, @Nullable @Nullable Block clickedBlock, @NotNull @NotNull BlockFace clickedFace)

### PlayerInteractEvent

public PlayerInteractEvent(@NotNull @NotNull Player who, @NotNull @NotNull Action action, @Nullable @Nullable ItemStack item, @Nullable @Nullable Block clickedBlock, @NotNull @NotNull BlockFace clickedFace, @Nullable @Nullable EquipmentSlot hand)

### PlayerInteractEvent

public PlayerInteractEvent(@NotNull @NotNull Player who, @NotNull @NotNull Action action, @Nullable @Nullable ItemStack item, @Nullable @Nullable Block clickedBlock, @NotNull @NotNull BlockFace clickedFace, @Nullable @Nullable EquipmentSlot hand, @Nullable @Nullable Location interactionPoint)

## Method Details

### getAction

@NotNull public @NotNull Action getAction()
Returns the action type

Returns:
  Action returns the type of interaction

### isCancelled

@Deprecated public 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.
Gets the cancellation state of this event. Set to true if you want to prevent buckets from placing water and so forth

Specified by:
  `isCancelled` in interface `Cancellable`
Returns:
  boolean cancellation state

### 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)

Specified by:
  `setCancelled` in interface `Cancellable`
Parameters:
  `cancel` - true if you wish to cancel this event

### getItem

@Nullable public @Nullable ItemStack getItem()
Returns the item in hand represented by this event

Returns:
  ItemStack the item used

### getMaterial

@NotNull public @NotNull Material getMaterial()
Convenience method. Returns the material of the item represented by this event

Returns:
  Material the material of the item used

### hasBlock

public boolean hasBlock()
Check if this event involved a block

Returns:
  boolean true if it did

### hasItem

public boolean hasItem()
Check if this event involved an item

Returns:
  boolean true if it did

### isBlockInHand

public boolean isBlockInHand()
Convenience method to inform the user whether this was a block placement event.

Returns:
  boolean true if the item in hand was a block

### getClickedBlock

@Nullable public @Nullable Block getClickedBlock()
Returns the clicked block

Returns:
  Block returns the block clicked with this item.

### getBlockFace

@NotNull public @NotNull BlockFace getBlockFace()
Returns the face of the block that was clicked

Returns:
  BlockFace returns the face of the block that was clicked

### useInteractedBlock

@NotNull public @NotNull Event.Result useInteractedBlock()
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

Returns:
  the action to take with the interacted block

### setUseInteractedBlock

public void setUseInteractedBlock(@NotNull @NotNull Event.Result useInteractedBlock)

Parameters:
  `useInteractedBlock` - the action to take with the interacted block

### useItemInHand

@NotNull public @NotNull 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.

Returns:
  the action to take with the item in hand

### setUseItemInHand

public void setUseItemInHand(@NotNull @NotNull Event.Result useItemInHand)

Parameters:
  `useItemInHand` - the action to take with the item in hand

### getHand

@Nullable public @Nullable EquipmentSlot getHand()
The hand used to perform this interaction. May be null in the case of `Action.PHYSICAL`.

Returns:
  the hand used to interact. May be null.

### getInteractionPoint

@Nullable public @Nullable Location getInteractionPoint()
The exact point at which the interaction occurred. May be null.

Returns:
  the exact interaction point. May be null.

### getHandlers

@NotNull public @NotNull HandlerList getHandlers()

Specified by:
  `getHandlers` in class `Event`

### getHandlerList

@NotNull public static @NotNull HandlerList getHandlerList()