类 InventoryView

java.lang.Object
org.bukkit.inventory.InventoryView

public abstract class InventoryView extends Object
代表连接两个物品栏(从UI上理解即为上下各一个)与单个玩家 (其物品栏可能也可能不是视图代表的两个物品栏之一)的背包视图.

注意: 如果你实现了这个接口却未能满足方法的约定 (未能完全实现既定的功能), 将不保证游戏能正常工作.

原文:Represents a view linking two inventories and a single player (whose inventory may or may not be one of the two).

Note: If you implement this interface but fail to satisfy the expected contracts of certain methods, there's no guarantee that the game will work as it should.

  • 字段详细资料

  • 构造器详细资料

    • InventoryView

      public InventoryView()
  • 方法详细资料

    • getTopInventory

      @NotNull public abstract @NotNull Inventory getTopInventory()
      获取此窗口视图上方的物品栏.

      原文:Get the upper inventory involved in this transaction.

      返回:
      物品栏
    • getBottomInventory

      @NotNull public abstract @NotNull Inventory getBottomInventory()
      获取此窗口视图下方的物品栏 (通常是玩家背包).

      原文:Get the lower inventory involved in this transaction.

      返回:
      物品栏
    • getPlayer

      @NotNull public abstract @NotNull HumanEntity getPlayer()
      获取正查看此窗口的玩家.

      原文:Get the player viewing.

      返回:
      玩家
    • getType

      @NotNull public abstract @NotNull InventoryType getType()
      判断该事件中物品栏的类型. 这表示将被展示的窗口样式. 该方法永不会返回PLAYER值.

      原文:Determine the type of inventory involved in the transaction. This indicates the window style being shown. It will never return PLAYER, since that is common to all windows.

      返回:
      物品栏类型
    • setItem

      public void setItem(int slot, @Nullable @Nullable ItemStack item)
      设置该物品栏指定槽位的物品.

      注意: 如果id是 -999, 那么该物品将被扔在地面上. 然而, 这不是必须的行为. (所以你还是通过常规方法扔物品, 毕竟写个-999不看文档的人谁看得懂呢...233).

      原文:Sets one item in this inventory view by its raw slot ID.

      Note: If slot ID -999 is chosen, it may be expected that the item is dropped on the ground. This is not required behaviour, however.

      参数:
      slot - 槽位id (可以通过InventoryClickEvent.getRawSlot()获取)
      item - 要放置的物品, null则清除
    • getItem

      @Nullable public @Nullable ItemStack getItem(int slot)
      获取该物品栏指定槽位的物品.

      原文:Gets one item in this inventory view by its raw slot ID.

      参数:
      slot - 槽位id (可以通过InventoryClickEvent.getRawSlot()获取)
      返回:
      该槽位内的物品
    • setCursor

      public final void setCursor(@Nullable @Nullable ItemStack item)
      设置玩家客户端鼠标光标所指位置上的物品.

      原文:Sets the item on the cursor of one of the viewing players.

      参数:
      item - 要放置的物品, null则清除
    • getCursor

      @Nullable public final @Nullable ItemStack getCursor()
      获取玩家客户端鼠标光标所指位置上的物品.

      原文:Get the item on the cursor of one of the viewing players.

      返回:
      光标所指物品, 如果所指槽位为空返回null
    • getInventory

      @Nullable public final @Nullable Inventory getInventory(int rawSlot)
      Gets the inventory corresponding to the given raw slot ID. If the slot ID is OUTSIDE null will be returned, otherwise behaviour for illegal and negative slot IDs is undefined. May be used with convertSlot(int) to directly index an underlying inventory.
      参数:
      rawSlot - The raw slot ID.
      返回:
      corresponding inventory, or null
    • convertSlot

      public final int convertSlot(int rawSlot)
      将原始槽位id转换为本地槽位id (本地槽位id适用于当前正在查看的两个物品栏).

      若原始槽位id指向窗口的上半部分的物品栏, 那么返回的值不变, 此时返回值适用于getTopInventory().getItem(); 若该id指向底部物品栏, 返回的值将与原始槽位id不同, 此时返回值适用于getBottomInventory().getItem().

      这是玩家背包的一个实例(来自代码注释):

      原文:Converts a raw slot ID into its local slot ID into whichever of the two inventories the slot points to.

      Raw Slots(原始槽位id):
      
       5             1  2     0
       6             3  4
       7
       8           45
       9  10 11 12 13 14 15 16 17
       18 19 20 21 22 23 24 25 26
       27 28 29 30 31 32 33 34 35
       36 37 38 39 40 41 42 43 44
      
       转换后:
      
       39             1  2     0
       38             3  4
       37
       36          40
       9  10 11 12 13 14 15 16 17
       18 19 20 21 22 23 24 25 26
       27 28 29 30 31 32 33 34 35
       0  1  2  3  4  5  6  7  8

      原文:If the raw slot refers to the upper inventory, it will be returned unchanged and thus be suitable for getTopInventory().getItem(); if it refers to the lower inventory, the output will differ from the input and be suitable for getBottomInventory().getItem().

      参数:
      rawSlot - 原始槽位id
      返回:
      转换后的槽位id
    • getSlotType

      @NotNull public final InventoryType.SlotType getSlotType(int slot)
      Determine the type of the slot by its raw slot ID.

      If the type of the slot is unknown, then InventoryType.SlotType.CONTAINER will be returned.

      参数:
      slot - The raw slot ID
      返回:
      the slot type
    • close

      public final void close()
      关闭该窗口视图.

      原文:Closes the inventory view.

    • countSlots

      public final int countSlots()
      Check the total number of slots in this view, combining the upper and lower inventories.

      Note though that it's possible for this to be greater than the sum of the two inventories if for example some slots are not being used.

      返回:
      The total size
    • setProperty

      public final boolean setProperty(@NotNull @NotNull InventoryView.Property prop, int value)
      Sets an extra property of this inventory if supported by that inventory, for example the state of a progress bar.
      参数:
      prop - the window property to update
      value - the new value for the window property
      返回:
      true if the property was updated successfully, false if the property is not supported by that inventory
    • getTitle

      @NotNull public abstract @NotNull String getTitle()
      获取物品栏窗口的标题.

      原文:Get the title of this inventory window.

      返回:
      标题
    • getOriginalTitle

      @NotNull public abstract @NotNull String getOriginalTitle()
      Get the original title of this inventory window, before any changes were made using setTitle(String).
      返回:
      the original title
    • setTitle

      public abstract void setTitle(@NotNull @NotNull String title)
      Sets the title of this inventory window to the specified title if the inventory window supports it.

      Note if the inventory does not support titles that can be changed (ie, it is not creatable or viewed by a player), then this method will throw an exception.

      参数:
      title - The new title.