类 InventoryClickEvent

所有已实现的接口:
Cancellable
直接已知子类:
CraftItemEvent, InventoryCreativeEvent, SmithItemEvent

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

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

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

如果一定要调用这些方法,请使用 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.

  • 构造器详细资料

  • 方法详细资料

    • 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.

      返回:
      是否右击背包
      另请参阅:
    • isLeftClick

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

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

      返回:
      是否左击背包
      另请参阅:
    • 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按键
      另请参阅:
    • 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
      另请参阅:
    • 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()