程序包 org.bukkit.event.inventory

# 类 InventoryClickEvent

java.lang.Object
org.bukkit.event.Event
org.bukkit.event.inventory.InventoryEvent
org.bukkit.event.inventory.InventoryInteractEvent
org.bukkit.event.inventory.InventoryClickEvent

所有已实现的接口:
  `Cancellable`

直接已知子类:
  `CraftItemEvent`, `InventoryCreativeEvent`, `SmithItemEvent`

public class InventoryClickEvent extends InventoryInteractEvent
当玩家点击物品栏中的格子时触发事件事件.
译注：事实上打开任意容器的物品栏(包括玩家的背包)后点击任何一个地方都会触发这个事件。

由于`InventoryClickEvent`是通过修改`物品栏` 的实现类来触发的，所以并非所有与`物品栏`相关的方法都是安全的。

下面这些属于`HumanEntity`和 `InventoryView`的方法不应该被处理 `InventoryClickEvent`事件的 `事件处理器`调用

- `HumanEntity.closeInventory()`
- `HumanEntity.openInventory(Inventory)`
- `HumanEntity.openWorkbench(Location, boolean)`
- `HumanEntity.openEnchanting(Location, boolean)`
- `InventoryView.close()`

如果一定要调用这些方法，请使用 `BukkitScheduler.runTask(Plugin, Runnable)`来执行 ，这个方法将在下一个tick执行你的任务。
注意：上面列出来的这些方法并不全，可能还有其它的方法也存在问题。

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.

- ## 嵌套类概要

  ## 从类继承的嵌套类/接口 org.bukkit.event.Event

  `Event.Result`

- ## 字段概要

  ### 从类继承的字段 org.bukkit.event.inventory.InventoryEvent

  `transaction`

- ## 构造器概要

  构造器
  构造器
  说明
  `InventoryClickEvent(@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)`

- ## 方法概要

  修饰符和类型
  方法
  说明
  `@NotNull InventoryAction`
  `getAction()`
  Gets the InventoryAction that triggered this event.
  `@NotNull ClickType`
  `getClick()`
  获取本事件的ClickType.
  `@Nullable Inventory`
  `getClickedInventory()`
  Gets the inventory corresponding to the clicked slot.
  `@Nullable ItemStack`
  `getCurrentItem()`
  获取被点击的格子的物品
  `@Nullable ItemStack`
  `getCursor()`
  获取被光标所拿起来的物品
  `static @NotNull HandlerList`
  `getHandlerList()`
  `@NotNull HandlerList`
  `getHandlers()`
  `int`
  `getHotbarButton()`
  如果ClickType是NUMVER_KEY（按下数字切换物品），这个方法将返回按下的键的索引（0-8）
  `int`
  `getRawSlot()`
  返回点击的原始格子序号，可传递给`#getItem(int)`。
  `int`
  `getSlot()`
  返回点击的格子序号，可传递给`Inventory.getItem(int)`。
  `@NotNull InventoryType.SlotType`
  `getSlotType()`
  获取被点击的格子的类型.
  `boolean`
  `isLeftClick()`
  获取是否左击背包
  `boolean`
  `isRightClick()`
  获取是否右击背包
  `boolean`
  `isShiftClick()`
  获取是否按住shift点击背包
  `void`
  `setCurrentItem(@Nullable ItemStack stack)`
  Sets the ItemStack currently in the clicked slot.
  `void`
  `setCursor(@Nullable ItemStack stack)`
  已过时。
  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.

  ### 从类继承的方法 org.bukkit.event.inventory.InventoryInteractEvent

  `getResult, getWhoClicked, isCancelled, setCancelled, setResult`

  ### 从类继承的方法 org.bukkit.event.inventory.InventoryEvent

  `getInventory, getView, getViewers`

  ### 从类继承的方法 org.bukkit.event.Event

  `getEventName, isAsynchronous`

  ### 从类继承的方法 java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 构造器详细资料

  - ### InventoryClickEvent

    public InventoryClickEvent(@NotNull @NotNull InventoryView view, @NotNull @NotNull InventoryType.SlotType type, int slot, @NotNull @NotNull ClickType click, @NotNull @NotNull InventoryAction action)

  - ### InventoryClickEvent

    public InventoryClickEvent(@NotNull @NotNull InventoryView view, @NotNull @NotNull InventoryType.SlotType type, int slot, @NotNull @NotNull ClickType click, @NotNull @NotNull InventoryAction action, int key)

- ## 方法详细资料

  - ### getSlotType

    @NotNull public @NotNull InventoryType.SlotType getSlotType()
    获取被点击的格子的类型.

    原文:Gets the type of slot that was clicked.

    返回:
      格子类型

  - ### getCursor

    @Nullable public @Nullable ItemStack getCursor()
    获取被光标所拿起来的物品

    原文:Gets the current ItemStack on the cursor.

    返回:
      被光标所拿起来的物品

  - ### getCurrentItem

    @Nullable public @Nullable ItemStack getCurrentItem()
    获取被点击的格子的物品

    原文:Gets the ItemStack currently in the clicked slot.

    返回:
      被点击的物品

  - ### isRightClick

    public boolean isRightClick()
    获取是否右击背包

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

    返回:
      是否右击背包
    另请参阅:
      - `ClickType.isRightClick()`

  - ### isLeftClick

    public boolean isLeftClick()
    获取是否左击背包

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

    返回:
      是否左击背包
    另请参阅:
      - `ClickType.isLeftClick()`

  - ### isShiftClick

    public boolean isShiftClick()
    获取是否按住shift点击背包

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

    返回:
      是否使用Shift或Ctrl按键
    另请参阅:
      - `ClickType.isShiftClick()`

  - ### setCursor

    @Deprecated public void setCursor(@Nullable @Nullable ItemStack stack)
    已过时。
    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.
    参数:
      `stack` - the new cursor item

  - ### setCurrentItem

    public void setCurrentItem(@Nullable @Nullable ItemStack stack)
    Sets the ItemStack currently in the clicked slot.
    参数:
      `stack` - the item to be placed in the current slot

  - ### getClickedInventory

    @Nullable public @Nullable Inventory getClickedInventory()
    Gets the inventory corresponding to the clicked slot.
    返回:
      inventory, or null if clicked outside
    另请参阅:
      - `InventoryView.getInventory(int)`

  - ### getSlot

    public int getSlot()
    返回点击的格子序号，可传递给`Inventory.getItem(int)`。注意由于连接两个不同背包的视图，可能两个格子都是同一个格子序号

    原文: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.

    返回:
      格子序号

  - ### getRawSlot

    public int getRawSlot()
    返回点击的原始格子序号，可传递给`#getItem(int)`。这个序号对每个视图是唯一的。

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

    返回:
      格子序号

  - ### getHotbarButton

    public int getHotbarButton()
    如果ClickType是NUMVER_KEY（按下数字切换物品），这个方法将返回按下的键的索引（0-8）

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

    返回:
      按下的数字减1（范围0-8），如果不是NUMBER_KEY动作为-1

  - ### getAction

    @NotNull public @NotNull InventoryAction 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.

    返回:
      the InventoryAction that triggered this event.

  - ### getClick

    @NotNull public @NotNull ClickType getClick()
    获取本事件的ClickType.

    获取到的结果与其它插件对其的改动相隔离.

    原文:Gets the ClickType for this event.

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

    返回:
      背包点击类型

  - ### getHandlers

    @NotNull public @NotNull HandlerList getHandlers()
    覆盖:
      `getHandlers` 在类中 `InventoryEvent`

  - ### getHandlerList

    @NotNull public static @NotNull HandlerList getHandlerList()