Class InventoryClickEvent
- All Implemented Interfaces:
- Cancellable
- Direct Known Subclasses:
- CartographyItemEvent,- CraftItemEvent,- InventoryCreativeEvent,- SmithItemEvent
 In case of a drag action within an inventory, InventoryClickEvent is never called.
 Instead, InventoryDragEvent is called at the end of the drag.
 
Because InventoryClickEvent occurs within a modification of the Inventory, not all Inventory related methods are safe to use.
Methods that change the view a player is looking at should never be invoked by an EventHandler for InventoryClickEvent using the HumanEntity or InventoryView associated with this event. Examples of these include:
- HumanEntity.closeInventory()
- HumanEntity.openInventory(Inventory)
- HumanEntity.openWorkbench(Location, boolean)
- HumanEntity.openEnchanting(Location, boolean)
- InventoryView.close()
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 BukkitScheduler.runTask(Plugin, Runnable), which would execute the task on the next tick, would
 work as well.
- 
Nested Class SummaryNested classes/interfaces inherited from class org.bukkit.event.EventEvent.Result
- 
Field SummaryFields inherited from class org.bukkit.event.inventory.InventoryEventtransaction
- 
Constructor SummaryConstructorsConstructorDescriptionInventoryClickEvent(@NotNull InventoryView view, @NotNull InventoryType.SlotType type, int slot, @NotNull ClickType click, @NotNull InventoryAction action) InventoryClickEvent(@NotNull InventoryView view, @NotNull InventoryType.SlotType type, int slot, @NotNull ClickType click, @NotNull InventoryAction action, int key) 
- 
Method SummaryModifier and TypeMethodDescriptionGets the InventoryAction that triggered this event.getClick()Gets the ClickType for this event.Gets the inventory corresponding to the clicked slot.Gets the ItemStack currently in the clicked slot.Gets the current ItemStack on the cursor.static @NotNull HandlerListintIf the ClickType is NUMBER_KEY, this method will return the index of the pressed key (0-8).intThe raw slot number clicked, ready for passing to#getItem(int)This slot number is unique for the view.intgetSlot()The slot number that was clicked, ready for passing toInventory.getItem(int).Gets the type of slot that was clicked.booleanGets whether or not the ClickType for this event represents a left click.booleanGets whether or not the ClickType for this event represents a right click.booleanGets whether the ClickType for this event indicates that the key was pressed down when the click was made.voidsetCurrentItem(@Nullable ItemStack stack) Sets the ItemStack currently in the clicked slot.voidDeprecated.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.Methods inherited from class org.bukkit.event.inventory.InventoryInteractEventgetResult, getWhoClicked, isCancelled, setCancelled, setResultMethods inherited from class org.bukkit.event.inventory.InventoryEventgetInventory, getView, getViewersMethods inherited from class org.bukkit.event.EventcallEvent, getEventName, isAsynchronous
- 
Constructor Details- 
InventoryClickEventpublic InventoryClickEvent(@NotNull @NotNull InventoryView view, @NotNull @NotNull InventoryType.SlotType type, int slot, @NotNull @NotNull ClickType click, @NotNull @NotNull InventoryAction action) 
- 
InventoryClickEventpublic InventoryClickEvent(@NotNull @NotNull InventoryView view, @NotNull @NotNull InventoryType.SlotType type, int slot, @NotNull @NotNull ClickType click, @NotNull @NotNull InventoryAction action, int key) 
 
- 
- 
Method Details- 
getSlotTypeGets the type of slot that was clicked.- Returns:
- the slot type
 
- 
getCursorGets the current ItemStack on the cursor.- Returns:
- the cursor ItemStack
 
- 
getCurrentItemGets the ItemStack currently in the clicked slot.- Returns:
- the item in the clicked slot
 
- 
isRightClickpublic boolean 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:
 
- 
isLeftClickpublic boolean 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:
 
- 
isShiftClickpublic boolean 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:
 
- 
setCursorDeprecated.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.Sets the item on the cursor.- Parameters:
- stack- the new cursor item
 
- 
setCurrentItemSets the ItemStack currently in the clicked slot.- Parameters:
- stack- the item to be placed in the current slot
 
- 
getClickedInventoryGets the inventory corresponding to the clicked slot.- Returns:
- inventory, or null if clicked outside
- See Also:
 
- 
getSlotpublic int getSlot()The slot number that was clicked, ready for passing toInventory.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.
 
- 
getRawSlotpublic int getRawSlot()The raw slot number clicked, ready for passing to#getItem(int)This slot number is unique for the view.- Returns:
- the slot number
 
- 
getHotbarButtonpublic int 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
 
- 
getActionGets 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.
 
- 
getClickGets the ClickType for this event.This is insulated against changes to the inventory by other plugins. - Returns:
- the type of inventory click
 
- 
getHandlers- Overrides:
- getHandlersin class- InventoryEvent
 
- 
getHandlerList
 
-