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
Called when a player interacts with an object or air.
This event will fire as cancelled if the vanilla behavior is to do nothing (e.g interacting with air)
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description ActiongetAction()Returns the action typeBlockFacegetBlockFace()Returns the face of the block that was clickedBlockgetClickedBlock()Returns the clicked blockstatic HandlerListgetHandlerList()HandlerListgetHandlers()ItemStackgetItem()Returns the item in hand represented by this eventMaterialgetMaterial()Convenience method.booleanhasBlock()Check if this event involved a blockbooleanhasItem()Check if this event involved an itembooleanisBlockInHand()Convenience method to inform the user whether this was a block placement event.booleanisCancelled()Gets the cancellation state of this event.voidsetCancelled(boolean cancel)Sets the cancellation state of this event.voidsetUseInteractedBlock(Event.Result useInteractedBlock)voidsetUseItemInHand(Event.Result useItemInHand)Event.ResultuseInteractedBlock()This controls the action to take with the block (if any) that was clicked on.Event.ResultuseItemInHand()This controls the action to take with the item the player is holding.
-
Field Details
-
Constructor Details
-
Method Details
-
getAction
Returns the action type- Returns:
- Action returns the type of interaction
-
isCancelled
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- Specified by:
isCancelledin interfaceCancellable- 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 pluginsCanceling 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:
setCancelledin interfaceCancellable- Parameters:
cancel- true if you wish to cancel this event
-
getItem
Returns the item in hand represented by this event- Returns:
- ItemStack the item used
-
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
Returns the clicked block- Returns:
- Block returns the block clicked with this item.
-
getBlockFace
Returns the face of the block that was clicked- Returns:
- BlockFace returns the face of the block that was clicked
-
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
- Parameters:
useInteractedBlock- the action to take with the interacted block
-
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
- Parameters:
useItemInHand- the action to take with the item in hand
-
getHandlers
- Specified by:
getHandlersin classEvent
-
getHandlerList
-