Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.event.inventory.InventoryClickEvent Class Reference
Inheritance diagram for org.bukkit.event.inventory.InventoryClickEvent:
org.bukkit.event.inventory.InventoryInteractEvent org.bukkit.event.inventory.InventoryEvent org.bukkit.event.Cancellable org.bukkit.event.Event org.bukkit.event.inventory.CraftItemEvent org.bukkit.event.inventory.InventoryCreativeEvent

Public Member Functions

 InventoryClickEvent (InventoryView view, SlotType type, int slot, boolean right, boolean shift)
 
 InventoryClickEvent (InventoryView view, SlotType type, int slot, ClickType click, InventoryAction action)
 
 InventoryClickEvent (InventoryView view, SlotType type, int slot, ClickType click, InventoryAction action, int key)
 
SlotType getSlotType ()
 
ItemStack getCursor ()
 
ItemStack getCurrentItem ()
 
boolean isRightClick ()
 
boolean isLeftClick ()
 
boolean isShiftClick ()
 
void setCursor (ItemStack stack)
 
void setCurrentItem (ItemStack stack)
 
int getSlot ()
 
int getRawSlot ()
 
int getHotbarButton ()
 
InventoryAction getAction ()
 
ClickType getClick ()
 
HandlerList getHandlers ()
 
- Public Member Functions inherited from org.bukkit.event.inventory.InventoryInteractEvent
 InventoryInteractEvent (InventoryView transaction)
 
HumanEntity getWhoClicked ()
 
void setResult (Result newResult)
 
Result getResult ()
 
boolean isCancelled ()
 
void setCancelled (boolean toCancel)
 
- Public Member Functions inherited from org.bukkit.event.inventory.InventoryEvent
 InventoryEvent (InventoryView transaction)
 
Inventory getInventory ()
 
List< HumanEntitygetViewers ()
 
InventoryView getView ()
 
HandlerList getHandlers ()
 
- 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 ()
 
- Static Public Member Functions inherited from org.bukkit.event.inventory.InventoryEvent
static HandlerList getHandlerList ()
 

Additional Inherited Members

- Protected Attributes inherited from org.bukkit.event.inventory.InventoryEvent
InventoryView transaction
 

Detailed Description

This event is called when a player clicks a slot in an inventory.

Because InventoryClickEvent occurs within a modification of the Inventory, not all Inventory related methods are safe to use.

The following should never be invoked by an EventHandler for InventoryClickEvent using the HumanEntity or InventoryView associated with this event:

To invoke one of these methods, schedule a task using BukkitScheduler#runTask(Plugin, Runnable), which will run the task on the next tick. Also be aware that this is not an exhaustive list, and other methods could potentially create issues as well.

Assuming the EntityHuman associated with this event is an instance of a Player, manipulating the MaxStackSize or contents of an Inventory will require an Invocation of Player#updateInventory().

Modifications to slots that are modified by the results of this InventoryClickEvent can be overwritten. To change these slots, this event should be cancelled and all desired changes to the inventory applied. Alternatively, scheduling a task using Plugin, Runnable), which would execute the task on the next tick, would work as well.

Definition at line 46 of file InventoryClickEvent.java.

Member Function Documentation

InventoryAction org.bukkit.event.inventory.InventoryClickEvent.getAction ( )

Gets the InventoryAction that triggered this event.

This action cannot be changed, and represents what the normal outcome of the event will be. To change the behavior of this InventoryClickEvent, changes must be manually applied.

Returns
the InventoryAction that triggered this event.

Definition at line 206 of file InventoryClickEvent.java.

206  {
207  return action;
208  }
ClickType org.bukkit.event.inventory.InventoryClickEvent.getClick ( )

Gets the ClickType for this event.

This is insulated against changes to the inventory by other plugins.

Returns
the type of inventory click

Definition at line 217 of file InventoryClickEvent.java.

217  {
218  return click;
219  }
ItemStack org.bukkit.event.inventory.InventoryClickEvent.getCurrentItem ( )

Gets the ItemStack currently in the clicked slot.

Returns
the item in the clicked

Definition at line 98 of file InventoryClickEvent.java.

References org.bukkit.inventory.InventoryView.getItem(), org.bukkit.event.inventory.InventoryEvent.getView(), and org.bukkit.event.inventory.InventoryType.SlotType.OUTSIDE.

98  {
99  if (slot_type == SlotType.OUTSIDE) {
100  return current;
101  }
102  return getView().getItem(rawSlot);
103  }
ItemStack org.bukkit.event.inventory.InventoryClickEvent.getCursor ( )

Gets the current ItemStack on the cursor.

Returns
the cursor ItemStack

Definition at line 89 of file InventoryClickEvent.java.

References org.bukkit.inventory.InventoryView.getCursor(), and org.bukkit.event.inventory.InventoryEvent.getView().

89  {
90  return getView().getCursor();
91  }
int org.bukkit.event.inventory.InventoryClickEvent.getHotbarButton ( )

If the ClickType is NUMBER_KEY, this method will return the index of the pressed key (0-8).

Returns
the number on the key minus 1 (range 0-8); or -1 if not a NUMBER_KEY action

Definition at line 193 of file InventoryClickEvent.java.

193  {
194  return hotbarKey;
195  }
int org.bukkit.event.inventory.InventoryClickEvent.getRawSlot ( )

The raw slot number clicked, ready for passing to #getItem(int) This slot number is unique for the view.

Returns
the slot number

Definition at line 182 of file InventoryClickEvent.java.

182  {
183  return rawSlot;
184  }
int org.bukkit.event.inventory.InventoryClickEvent.getSlot ( )

The slot number that was clicked, ready for passing to Inventory#getItem(int). Note that there may be two slots with the same slot number, since a view links two different inventories.

Returns
The slot number.

Definition at line 172 of file InventoryClickEvent.java.

172  {
173  return whichSlot;
174  }
SlotType org.bukkit.event.inventory.InventoryClickEvent.getSlotType ( )

Gets the type of slot that was clicked.

Returns
the slot type

Definition at line 80 of file InventoryClickEvent.java.

80  {
81  return slot_type;
82  }
boolean org.bukkit.event.inventory.InventoryClickEvent.isLeftClick ( )

Gets whether or not the ClickType for this event represents a left click.

Returns
true if the ClickType uses the left mouse button.
See also
ClickType::isLeftClick()

Definition at line 123 of file InventoryClickEvent.java.

References org.bukkit.event.inventory.ClickType.isLeftClick().

123  {
124  return click.isLeftClick();
125  }
boolean org.bukkit.event.inventory.InventoryClickEvent.isRightClick ( )

Gets whether or not the ClickType for this event represents a right click.

Returns
true if the ClickType uses the right mouse button.
See also
ClickType::isRightClick()

Definition at line 112 of file InventoryClickEvent.java.

References org.bukkit.event.inventory.ClickType.isRightClick().

112  {
113  return click.isRightClick();
114  }
boolean org.bukkit.event.inventory.InventoryClickEvent.isShiftClick ( )

Gets whether the ClickType for this event indicates that the key was pressed down when the click was made.

Returns
true if the ClickType uses Shift or Ctrl.
See also
ClickType::isShiftClick()

Definition at line 134 of file InventoryClickEvent.java.

References org.bukkit.event.inventory.ClickType.isShiftClick().

134  {
135  return click.isShiftClick();
136  }
void org.bukkit.event.inventory.InventoryClickEvent.setCurrentItem ( ItemStack  stack)

Sets the ItemStack currently in the clicked slot.

Parameters
stackthe item to be placed in the current slot

Definition at line 157 of file InventoryClickEvent.java.

References org.bukkit.event.inventory.InventoryEvent.getView(), org.bukkit.event.inventory.InventoryType.SlotType.OUTSIDE, and org.bukkit.inventory.InventoryView.setItem().

157  {
158  if (slot_type == SlotType.OUTSIDE) {
159  current = stack;
160  } else {
161  getView().setItem(rawSlot, stack);
162  }
163  }
void setItem(int slot, ItemStack item)
void org.bukkit.event.inventory.InventoryClickEvent.setCursor ( ItemStack  stack)

Sets the item on the cursor.

Parameters
stackthe new cursor item
Deprecated:
This changes the ItemStack in their hand before any calculations are applied to the Inventory, which has a tendency to create inconsistencies between the Player and the server, and to make unexpected changes in the behavior of the clicked Inventory.

Definition at line 148 of file InventoryClickEvent.java.

References org.bukkit.event.inventory.InventoryEvent.getView(), and org.bukkit.inventory.InventoryView.setCursor().

148  {
149  getView().setCursor(stack);
150  }
final void setCursor(ItemStack item)

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