Class ObscuredInventory

java.lang.Object
xyz.xenondevs.invui.inventory.Inventory
xyz.xenondevs.invui.inventory.ObscuredInventory

public class ObscuredInventory extends Inventory
An Inventory that delegates to another Inventory while hiding certain slots.
  • Constructor Details

    • ObscuredInventory

      public ObscuredInventory(@NotNull @NotNull Inventory inventory, @NotNull @NotNull IntPredicate isObscured)
      Constructs a new ObscuredInventory.
      Parameters:
      inventory - The Inventory to delegate to.
      isObscured - A IntPredicate that returns true for slots that should be hidden.
  • Method Details

    • getSize

      public int getSize()
      Description copied from class: Inventory
      Gets the size of this Inventory.
      Specified by:
      getSize in class Inventory
      Returns:
      How many slots this Inventory has.
    • getMaxStackSizes

      public int @NotNull [] getMaxStackSizes()
      Description copied from class: Inventory
      Gets the array of max stack sizes for this Inventory.
      Specified by:
      getMaxStackSizes in class Inventory
      Returns:
      The array defining the max stack sizes for this Inventory
    • getMaxSlotStackSize

      public int getMaxSlotStackSize(int slot)
      Description copied from class: Inventory
      Gets the maximum stack size for a specific slot while ignoring max stack size of the ItemStack on it.
      Specified by:
      getMaxSlotStackSize in class Inventory
      Parameters:
      slot - The slot
      Returns:
      The maximum stack size on that slo
    • getItems

      @Nullable public @Nullable org.bukkit.inventory.ItemStack @NotNull [] getItems()
      Description copied from class: Inventory
      Gets a copy of the contents of this Inventory.

      It is guaranteed that this method will never return an air / empty item stack. Those are always represented by null.

      Specified by:
      getItems in class Inventory
      Returns:
      A deep copy of the ItemStacks this Inventory contains.
    • getUnsafeItems

      @Nullable public @Nullable org.bukkit.inventory.ItemStack @NotNull [] getUnsafeItems()
      Description copied from class: Inventory
      Gets the ItemStacks this Inventory contains. Depending on the implementation, this method may return a copy, a deep copy, or the actual backing item stack array. Modifying the returned array might or might not reflect in this Inventory.

      It is guaranteed that this method will never return an air / empty item stack. Those are always represented by null.

      Specified by:
      getUnsafeItems in class Inventory
      Returns:
      The ItemStacks this Inventory contains.
    • getItem

      @Nullable public @Nullable org.bukkit.inventory.ItemStack getItem(int slot)
      Description copied from class: Inventory
      Gets a clone of the ItemStack on that slot.

      It is guaranteed that this method will never return an air / empty item stack. Those are always represented by null.

      Specified by:
      getItem in class Inventory
      Parameters:
      slot - The slot
      Returns:
      The ItemStack on the given slot
    • getUnsafeItem

      @Nullable public @Nullable org.bukkit.inventory.ItemStack getUnsafeItem(int slot)
      Description copied from class: Inventory
      Gets the ItemStack on that slot. Depending on the implementation, this method may a copy of or the actual backing ItemStack.

      It is guaranteed that this method will never return an air / empty item stack. Those are always represented by null.

      Specified by:
      getUnsafeItem in class Inventory
      Parameters:
      slot - The slot
      Returns:
      The ItemStack on the given slot.
    • setCloneBackingItem

      protected void setCloneBackingItem(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack)
      Description copied from class: Inventory
      Clones the given ItemStack and sets in the backing array of this Inventory.

      This method should never be invoked with an air / empty item stack. Those should always be represented by null.

      Specified by:
      setCloneBackingItem in class Inventory
      Parameters:
      slot - The slot
      itemStack - The ItemStack to be set
    • setDirectBackingItem

      protected void setDirectBackingItem(int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack)
      Description copied from class: Inventory
      Sets the ItemStack in the backing array of this Inventory without explicitly cloning it. Depending on the implementation, the ItemStack might still be cloned.

      This method should never be invoked with an air / empty item stack. Those should always be represented by null.

      Specified by:
      setDirectBackingItem in class Inventory
      Parameters:
      slot - The slot
      itemStack - The ItemStack to be set
    • notifyWindows

      public void notifyWindows()
      Description copied from class: Inventory
      Notifies all Windows displaying this Inventory to update their representative ItemStacks. This method should only be called manually in very specific cases like when the ItemMeta of an ItemStack in this inventory has changed.
      Overrides:
      notifyWindows in class Inventory
    • callPreUpdateEvent

      public ItemPreUpdateEvent callPreUpdateEvent(@Nullable @Nullable UpdateReason updateReason, int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable @Nullable org.bukkit.inventory.ItemStack newItemStack)
      Description copied from class: Inventory
      Creates an ItemPreUpdateEvent and calls the Inventory.preUpdateHandler to handle it.
      Overrides:
      callPreUpdateEvent in class Inventory
      Parameters:
      updateReason - The UpdateReason.
      slot - The slot of the affected ItemStack.
      previousItemStack - The ItemStack that was previously on that slot.
      newItemStack - The ItemStack that will be on that slot.
      Returns:
      The ItemPreUpdateEvent after it has been handled by the Inventory.preUpdateHandler.
    • callPostUpdateEvent

      public void callPostUpdateEvent(@Nullable @Nullable UpdateReason updateReason, int slot, @Nullable @Nullable org.bukkit.inventory.ItemStack previousItemStack, @Nullable @Nullable org.bukkit.inventory.ItemStack newItemStack)
      Description copied from class: Inventory
      Creates an ItemPostUpdateEvent and calls the Inventory.postUpdateHandler to handle it.
      Overrides:
      callPostUpdateEvent in class Inventory
      Parameters:
      updateReason - The UpdateReason.
      slot - The slot of the affected ItemStack.
      previousItemStack - The ItemStack that was on that slot previously.
      newItemStack - The ItemStack that is on that slot now.
    • hasEventHandlers

      public boolean hasEventHandlers()
      Description copied from class: Inventory
      Whether this Inventory has any event handlers.
      Overrides:
      hasEventHandlers in class Inventory
      Returns:
      `true` if this Inventory has a pre- or post-update handler.
    • setPostUpdateHandler

      public void setPostUpdateHandler(@Nullable @Nullable Consumer<@NotNull ItemPostUpdateEvent> inventoryUpdatedHandler)
      Description copied from class: Inventory
      Sets a handler which is called every time after something has been updated in the Inventory.
      Overrides:
      setPostUpdateHandler in class Inventory
      Parameters:
      inventoryUpdatedHandler - The new handler
    • setPreUpdateHandler

      public void setPreUpdateHandler(@Nullable @Nullable Consumer<@NotNull ItemPreUpdateEvent> preUpdateHandler)
      Description copied from class: Inventory
      Sets a handler which is called every time something gets updated in the Inventory.
      Overrides:
      setPreUpdateHandler in class Inventory
      Parameters:
      preUpdateHandler - The new item update handler
    • getGuiPriority

      public int getGuiPriority()
      Description copied from class: Inventory
      Gets the priority for click actions in a Gui, such as shift clicking or cursor collection with multiple VirtualInventories.
      Overrides:
      getGuiPriority in class Inventory
      Returns:
      The priority for click actions, VirtualInventories with a higher priority get prioritized.
    • setGuiPriority

      public void setGuiPriority(int guiPriority)
      Description copied from class: Inventory
      Sets the priority for click actions in a Gui, such as shift-clicking or cursor collection with multiple VirtualInventories.
      Overrides:
      setGuiPriority in class Inventory
      Parameters:
      guiPriority - The priority for click actions, VirtualInventories with a higher priority get prioritized.