Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.event.player.PlayerInteractEvent Class Reference
Inheritance diagram for org.bukkit.event.player.PlayerInteractEvent:
org.bukkit.event.player.PlayerEvent org.bukkit.event.Cancellable org.bukkit.event.Event

Public Member Functions

 PlayerInteractEvent (final Player who, final Action action, final ItemStack item, final Block clickedBlock, final BlockFace clickedFace)
 
Action getAction ()
 
boolean isCancelled ()
 
void setCancelled (boolean cancel)
 
ItemStack getItem ()
 
Material getMaterial ()
 
boolean hasBlock ()
 
boolean hasItem ()
 
boolean isBlockInHand ()
 
Block getClickedBlock ()
 
BlockFace getBlockFace ()
 
Result useInteractedBlock ()
 
void setUseInteractedBlock (Result useInteractedBlock)
 
Result useItemInHand ()
 
void setUseItemInHand (Result useItemInHand)
 
HandlerList getHandlers ()
 
- Public Member Functions inherited from org.bukkit.event.player.PlayerEvent
 PlayerEvent (final Player who)
 
final Player getPlayer ()
 
- Public Member Functions inherited from org.bukkit.event.Event
 Event ()
 
 Event (boolean isAsync)
 
String getEventName ()
 
abstract HandlerList getHandlers ()
 
final boolean isAsynchronous ()
 

Static Public Member Functions

static HandlerList getHandlerList ()
 

Protected Attributes

ItemStack item
 
Action action
 
Block blockClicked
 
BlockFace blockFace
 
- Protected Attributes inherited from org.bukkit.event.player.PlayerEvent
Player player
 

Detailed Description

Called when a player interacts with an object or air.

Definition at line 15 of file PlayerInteractEvent.java.

Member Function Documentation

Action org.bukkit.event.player.PlayerInteractEvent.getAction ( )

Returns the action type

Returns
Action returns the type of interaction

Definition at line 40 of file PlayerInteractEvent.java.

40  {
41  return action;
42  }
BlockFace org.bukkit.event.player.PlayerInteractEvent.getBlockFace ( )

Returns the face of the block that was clicked

Returns
BlockFace returns the face of the block that was clicked

Definition at line 138 of file PlayerInteractEvent.java.

138  {
139  return blockFace;
140  }
Block org.bukkit.event.player.PlayerInteractEvent.getClickedBlock ( )

Returns the clicked block

Returns
Block returns the block clicked with this item.

Definition at line 129 of file PlayerInteractEvent.java.

129  {
130  return blockClicked;
131  }
ItemStack org.bukkit.event.player.PlayerInteractEvent.getItem ( )

Returns the item in hand represented by this event

Returns
ItemStack the item used

Definition at line 74 of file PlayerInteractEvent.java.

74  {
75  return this.item;
76  }
Material org.bukkit.event.player.PlayerInteractEvent.getMaterial ( )

Convenience method. Returns the material of the item represented by this event

Returns
Material the material of the item used

Definition at line 84 of file PlayerInteractEvent.java.

References org.bukkit.inventory.ItemStack.getType(), and org.bukkit.event.player.PlayerInteractEvent.hasItem().

84  {
85  if (!hasItem()) {
86  return Material.AIR;
87  }
88 
89  return item.getType();
90  }
boolean org.bukkit.event.player.PlayerInteractEvent.hasBlock ( )

Check if this event involved a block

Returns
boolean true if it did

Definition at line 97 of file PlayerInteractEvent.java.

97  {
98  return this.blockClicked != null;
99  }
boolean org.bukkit.event.player.PlayerInteractEvent.hasItem ( )

Check if this event involved an item

Returns
boolean true if it did

Definition at line 106 of file PlayerInteractEvent.java.

Referenced by org.bukkit.event.player.PlayerInteractEvent.getMaterial(), and org.bukkit.event.player.PlayerInteractEvent.isBlockInHand().

106  {
107  return this.item != null;
108  }
boolean org.bukkit.event.player.PlayerInteractEvent.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

Definition at line 116 of file PlayerInteractEvent.java.

References org.bukkit.inventory.ItemStack.getType(), org.bukkit.event.player.PlayerInteractEvent.hasItem(), and org.bukkit.Material.isBlock().

116  {
117  if (!hasItem()) {
118  return false;
119  }
120 
121  return item.getType().isBlock();
122  }
boolean org.bukkit.event.player.PlayerInteractEvent.isCancelled ( )

Gets the cancellation state of this event. Set to true if you want to prevent buckets from placing water and so forth

Returns
boolean cancellation state

Implements org.bukkit.event.Cancellable.

Definition at line 50 of file PlayerInteractEvent.java.

References org.bukkit.event.Event.Result.DENY, and org.bukkit.event.player.PlayerInteractEvent.useInteractedBlock().

void org.bukkit.event.player.PlayerInteractEvent.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)

Parameters
canceltrue if you wish to cancel this event

Implements org.bukkit.event.Cancellable.

Definition at line 64 of file PlayerInteractEvent.java.

References org.bukkit.event.Event.Result.DEFAULT, org.bukkit.event.Event.Result.DENY, org.bukkit.event.player.PlayerInteractEvent.setUseInteractedBlock(), org.bukkit.event.player.PlayerInteractEvent.setUseItemInHand(), and org.bukkit.event.player.PlayerInteractEvent.useInteractedBlock().

64  {
65  setUseInteractedBlock(cancel ? Result.DENY : useInteractedBlock() == Result.DENY ? Result.DEFAULT : useInteractedBlock());
66  setUseItemInHand(cancel ? Result.DENY : useItemInHand() == Result.DENY ? Result.DEFAULT : useItemInHand());
67  }
void setUseInteractedBlock(Result useInteractedBlock)
void org.bukkit.event.player.PlayerInteractEvent.setUseInteractedBlock ( Result  useInteractedBlock)
Parameters
useInteractedBlockthe action to take with the interacted block

Definition at line 156 of file PlayerInteractEvent.java.

References org.bukkit.event.player.PlayerInteractEvent.useInteractedBlock().

Referenced by org.bukkit.event.player.PlayerInteractEvent.setCancelled().

156  {
157  this.useClickedBlock = useInteractedBlock;
158  }
void org.bukkit.event.player.PlayerInteractEvent.setUseItemInHand ( Result  useItemInHand)
Parameters
useItemInHandthe action to take with the item in hand

Definition at line 175 of file PlayerInteractEvent.java.

References org.bukkit.event.player.PlayerInteractEvent.useItemInHand().

Referenced by org.bukkit.event.player.PlayerInteractEvent.setCancelled().

Result org.bukkit.event.player.PlayerInteractEvent.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

Definition at line 149 of file PlayerInteractEvent.java.

Referenced by org.bukkit.event.player.PlayerInteractEvent.isCancelled(), org.bukkit.event.player.PlayerInteractEvent.setCancelled(), and org.bukkit.event.player.PlayerInteractEvent.setUseInteractedBlock().

149  {
150  return useClickedBlock;
151  }
Result org.bukkit.event.player.PlayerInteractEvent.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

Definition at line 168 of file PlayerInteractEvent.java.

Referenced by org.bukkit.event.player.PlayerInteractEvent.setUseItemInHand().

168  {
169  return useItemInHand;
170  }

The documentation for this class was generated from the following file: