interact — Events

on interactorg.bukkit.event.player.PlayerInteractEvent
Player1.0.0

Description

Fires when a player interacts with a block or air.

Variables

player
Player
org.bukkit.entity.Player
NullableNo

The player who interacted

action
String
java.lang.String
NullableNo

The action type: LEFT_CLICK_BLOCK, RIGHT_CLICK_BLOCK, LEFT_CLICK_AIR, RIGHT_CLICK_AIR, or PHYSICAL (triggering a block by stepping on or colliding with it, such as pressure plates or farmland).

block
Block
org.bukkit.block.Block
NullableYes

The block involved in the interaction, or null if the action targets air

item
ItemStack
org.bukkit.inventory.ItemStack
NullableYes

The item in the player's hand, or null if empty

Examples

on interact:
on interact: if action is "LEFT_CLICK_BLOCK": message player "You left clicked a block!"
on interact: if action is "RIGHT_CLICK_BLOCK": message player "You right clicked a block!" else if action is "LEFT_CLICK_AIR": message player "You left clicked in the air!"

Related (Player)