Class GlowInventory

java.lang.Object
net.glowstone.inventory.GlowInventory
All Implemented Interfaces:
Iterable<org.bukkit.inventory.ItemStack>, org.bukkit.inventory.Inventory
Direct Known Subclasses:
GlowAnvilInventory, GlowBeaconInventory, GlowBrewerInventory, GlowChestInventory, GlowCraftingInventory, GlowEnchantingInventory, GlowFurnaceInventory, GlowHorseInventory, GlowLlamaInventory, GlowMerchantInventory, GlowPlayerInventory, GlowSuperInventory

public class GlowInventory extends Object implements org.bukkit.inventory.Inventory
A class which represents an inventory.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
     
    GlowInventory(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type)
     
     
    GlowInventory(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type, int size)
     
     
    GlowInventory(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type, int size, String title)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack>
    addItem(org.bukkit.inventory.ItemStack... items)
     
    org.bukkit.inventory.ItemStack
    addItemStack(org.bukkit.inventory.ItemStack item, boolean ignoreMeta)
    Adds the contents of the given ItemStack to the inventory.
    void
    addViewer(org.bukkit.entity.HumanEntity viewer)
    Add a viewer to the inventory.
    @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack>
    all(@NotNull org.bukkit.Material material)
     
    @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack>
    all(org.bukkit.inventory.ItemStack item)
     
    void
     
    void
    clear(int index)
     
    int
     
    int
    consumeItem(int slot)
    Consumes an item in the given slot.
    int
    consumeItem(int slot, boolean wholeStack)
    Consumes an item or the full stack in the given slot.
    boolean
    contains(@NotNull org.bukkit.Material material)
     
    boolean
    contains(@NotNull org.bukkit.Material material, int amount)
     
    boolean
    contains(org.bukkit.inventory.ItemStack item)
     
    boolean
    contains(org.bukkit.inventory.ItemStack item, int amount)
     
    boolean
    containsAtLeast(org.bukkit.inventory.ItemStack item, int amount)
     
    int
    first(@NotNull org.bukkit.inventory.ItemStack item)
     
    int
    first(@NotNull org.bukkit.Material material)
     
    int
     
    org.bukkit.inventory.ItemStack @NotNull []
     
    org.bukkit.inventory.InventoryHolder
    The owner of this inventory.
    @Nullable org.bukkit.inventory.InventoryHolder
    getHolder(boolean snapshotBlockEntity)
     
    @NotNull org.bukkit.inventory.ItemStack
    getItem(int index)
     
    org.bukkit.Location
     
    int
    The inventory's maximum stack size.
    int
    Gets the number of slots in this inventory according to the protocol.
    int
     
    getSlot(int slot)
    Returns a certain slot.
    Returns the whole slot list.
    org.bukkit.event.inventory.InventoryType.SlotType
    getSlotType(int slot)
    Get the type of the specified slot.
    org.bukkit.inventory.ItemStack[]
     
    The inventory's name.
    org.bukkit.event.inventory.InventoryType
    The type of this inventory.
    @NotNull List<org.bukkit.entity.HumanEntity>
     
    Set<org.bukkit.entity.HumanEntity>
    Returns the set which contains viewers.
    void
    handleShiftClick(GlowPlayer player, org.bukkit.inventory.InventoryView view, int clickedSlot, org.bukkit.inventory.ItemStack clickedItem)
    Handle a shift click in this inventory by the specified player.
    protected void
    initialize(List<GlowInventorySlot> slots, Set<org.bukkit.entity.HumanEntity> viewers, org.bukkit.inventory.InventoryHolder owner, org.bukkit.event.inventory.InventoryType type, String title)
    Initializes some key components of this inventory.
    boolean
     
    boolean
    itemPlaceAllowed(int slot, org.bukkit.inventory.ItemStack stack)
    Check whether it is allowed for a player to insert the given ItemStack at the slot, regardless of the slot's current contents.
    boolean
    itemShiftClickAllowed(int slot, org.bukkit.inventory.ItemStack stack)
    Check whether, in a shift-click operation, an item of the specified type may be placed in the given slot.
    @NotNull ListIterator<org.bukkit.inventory.ItemStack>
     
    @NotNull ListIterator<org.bukkit.inventory.ItemStack>
    iterator(int index)
     
    void
    remove(@NotNull org.bukkit.inventory.ItemStack item)
     
    void
    remove(@NotNull org.bukkit.Material material)
     
    @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack>
    removeItem(org.bukkit.inventory.ItemStack... items)
     
    @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack>
    removeItemAnySlot(@NotNull org.bukkit.inventory.ItemStack... items)
     
    org.bukkit.inventory.ItemStack
    removeItemStack(org.bukkit.inventory.ItemStack item, boolean ignoreMeta)
    Removes the given ItemStack from the inventory.
    void
    removeViewer(org.bukkit.entity.HumanEntity viewer)
    Remove a viewer from the inventory.
    void
    setContents(org.bukkit.inventory.ItemStack[] items)
     
    void
    setItem(int index, org.bukkit.inventory.ItemStack item)
     
    void
    setMaxStackSize(int maxStackSize)
    The inventory's maximum stack size.
    void
    setStorageContents(org.bukkit.inventory.ItemStack[] items)
     
    void
    Set the custom title of this inventory or reset it to the default.
     
    org.bukkit.inventory.ItemStack
    tryToFillSlots(org.bukkit.inventory.ItemStack stack, int... slots)
    Tries to put the given items into the specified slots of this inventory from the start slot (inclusive) to the end slot (exclusive).

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • GlowInventory

      protected GlowInventory()
    • GlowInventory

      public GlowInventory(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type)
    • GlowInventory

      public GlowInventory(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type, int size)
    • GlowInventory

      public GlowInventory(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type, int size, String title)
  • Method Details

    • removeItemAnySlot

      @NotNull public @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack> removeItemAnySlot(@NotNull @NotNull org.bukkit.inventory.ItemStack... items) throws IllegalArgumentException
      Specified by:
      removeItemAnySlot in interface org.bukkit.inventory.Inventory
      Throws:
      IllegalArgumentException
    • initialize

      protected void initialize(List<GlowInventorySlot> slots, Set<org.bukkit.entity.HumanEntity> viewers, org.bukkit.inventory.InventoryHolder owner, org.bukkit.event.inventory.InventoryType type, String title)
      Initializes some key components of this inventory.

      This should be called in the constructor.

      Parameters:
      slots - List of slots this inventory has.
      viewers - Set for storage of current inventory viewers.
      owner - InventoryHolder which owns this Inventory.
      type - The inventory type.
      title - Inventory title, displayed in the client.
    • addViewer

      public void addViewer(org.bukkit.entity.HumanEntity viewer)
      Add a viewer to the inventory.
      Parameters:
      viewer - The HumanEntity to add.
    • removeViewer

      public void removeViewer(org.bukkit.entity.HumanEntity viewer)
      Remove a viewer from the inventory.
      Parameters:
      viewer - The HumanEntity to remove.
    • getViewersSet

      public Set<org.bukkit.entity.HumanEntity> getViewersSet()
      Returns the set which contains viewers.
      Returns:
      Viewers set.
    • getSlot

      public GlowInventorySlot getSlot(int slot)
      Returns a certain slot.
      Parameters:
      slot - index.
      Returns:
      The requested slot.
    • getSlotType

      public org.bukkit.event.inventory.InventoryType.SlotType getSlotType(int slot)
      Get the type of the specified slot.
      Parameters:
      slot - The slot number.
      Returns:
      The SlotType of the slot.
    • itemPlaceAllowed

      public boolean itemPlaceAllowed(int slot, org.bukkit.inventory.ItemStack stack)
      Check whether it is allowed for a player to insert the given ItemStack at the slot, regardless of the slot's current contents.

      Should return false for crafting output slots or armor slots which cannot accept the given item.

      Parameters:
      slot - The slot number.
      stack - The stack to add.
      Returns:
      Whether the stack can be added there.
    • itemShiftClickAllowed

      public boolean itemShiftClickAllowed(int slot, org.bukkit.inventory.ItemStack stack)
      Check whether, in a shift-click operation, an item of the specified type may be placed in the given slot.
      Parameters:
      slot - The slot number.
      stack - The stack to add.
      Returns:
      Whether the stack can be added there.
    • handleShiftClick

      public void handleShiftClick(GlowPlayer player, org.bukkit.inventory.InventoryView view, int clickedSlot, org.bukkit.inventory.ItemStack clickedItem)
      Handle a shift click in this inventory by the specified player.

      The default implementation distributes items from the right to the left and from the bottom to the top.

      Parameters:
      player - The player who clicked
      view - The inventory view in which was clicked
      clickedSlot - The slot in the view
      clickedItem - The item at which was clicked
    • tryToFillSlots

      public org.bukkit.inventory.ItemStack tryToFillSlots(org.bukkit.inventory.ItemStack stack, int... slots)
      Tries to put the given items into the specified slots of this inventory from the start slot (inclusive) to the end slot (exclusive).

      The slots are supplied in pairs, first the start then the end slots.

      This will first try to fill up all partial slots and if items are still left after doing so, it places them into the first empty slot.

      If no empty slot was found and there are still items left, they're returned from this method.

      Parameters:
      stack - The items to place down
      slots - Pairs of start/end slots
      Returns:
      The remaining items or null if non are remaining
    • getRawSlots

      public int getRawSlots()
      Gets the number of slots in this inventory according to the protocol.

      Some inventories have 0 slots in the protocol, despite having slots.

      Returns:
      The numbers of slots
    • getSize

      public int getSize()
      Specified by:
      getSize in interface org.bukkit.inventory.Inventory
    • getSlots

      public List<GlowInventorySlot> getSlots()
      Returns the whole slot list.
      Returns:
      Slot list.
    • setTitle

      public void setTitle(String title)
      Set the custom title of this inventory or reset it to the default.
      Parameters:
      title - The new title, or null to reset.
    • getViewers

      @NotNull public @NotNull List<org.bukkit.entity.HumanEntity> getViewers()
      Specified by:
      getViewers in interface org.bukkit.inventory.Inventory
    • getHolder

      @Nullable public @Nullable org.bukkit.inventory.InventoryHolder getHolder(boolean snapshotBlockEntity)
      Specified by:
      getHolder in interface org.bukkit.inventory.Inventory
    • iterator

      @NotNull public @NotNull ListIterator<org.bukkit.inventory.ItemStack> iterator()
      Specified by:
      iterator in interface org.bukkit.inventory.Inventory
      Specified by:
      iterator in interface Iterable<org.bukkit.inventory.ItemStack>
    • iterator

      @NotNull public @NotNull ListIterator<org.bukkit.inventory.ItemStack> iterator(int index)
      Specified by:
      iterator in interface org.bukkit.inventory.Inventory
    • getLocation

      public org.bukkit.Location getLocation()
      Specified by:
      getLocation in interface org.bukkit.inventory.Inventory
    • getItem

      @NotNull public @NotNull org.bukkit.inventory.ItemStack getItem(int index)
      Specified by:
      getItem in interface org.bukkit.inventory.Inventory
    • setItem

      public void setItem(int index, org.bukkit.inventory.ItemStack item)
      Specified by:
      setItem in interface org.bukkit.inventory.Inventory
    • addItem

      @NotNull public @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack> addItem(org.bukkit.inventory.ItemStack... items)
      Specified by:
      addItem in interface org.bukkit.inventory.Inventory
    • addItemStack

      public org.bukkit.inventory.ItemStack addItemStack(org.bukkit.inventory.ItemStack item, boolean ignoreMeta)
      Adds the contents of the given ItemStack to the inventory.
      Parameters:
      item - the ItemStack to add
      ignoreMeta - if true, can convert to items with different NBT data in order to stack with existing copies of those items, provided the material and damage value match
      Returns:
      the items that couldn't be added, or an empty stack if all were added
    • removeItem

      @NotNull public @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack> removeItem(org.bukkit.inventory.ItemStack... items)
      Specified by:
      removeItem in interface org.bukkit.inventory.Inventory
    • removeItemStack

      public org.bukkit.inventory.ItemStack removeItemStack(org.bukkit.inventory.ItemStack item, boolean ignoreMeta)
      Removes the given ItemStack from the inventory.
      Parameters:
      item - the ItemStack to remove
      ignoreMeta - if true, can choose an item with different NBT data, provided the material and damage value match
      Returns:
      the items that couldn't be removed, or an empty stack if all were removed
    • getContents

      public org.bukkit.inventory.ItemStack @NotNull [] getContents()
      Specified by:
      getContents in interface org.bukkit.inventory.Inventory
    • setContents

      public void setContents(org.bukkit.inventory.ItemStack[] items)
      Specified by:
      setContents in interface org.bukkit.inventory.Inventory
    • getStorageContents

      public org.bukkit.inventory.ItemStack[] getStorageContents()
      Specified by:
      getStorageContents in interface org.bukkit.inventory.Inventory
    • setStorageContents

      public void setStorageContents(org.bukkit.inventory.ItemStack[] items) throws IllegalArgumentException
      Specified by:
      setStorageContents in interface org.bukkit.inventory.Inventory
      Throws:
      IllegalArgumentException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • contains

      public boolean contains(@NotNull @NotNull org.bukkit.Material material)
      Specified by:
      contains in interface org.bukkit.inventory.Inventory
    • contains

      public boolean contains(org.bukkit.inventory.ItemStack item)
      Specified by:
      contains in interface org.bukkit.inventory.Inventory
    • contains

      public boolean contains(@NotNull @NotNull org.bukkit.Material material, int amount)
      Specified by:
      contains in interface org.bukkit.inventory.Inventory
    • contains

      public boolean contains(org.bukkit.inventory.ItemStack item, int amount)
      Specified by:
      contains in interface org.bukkit.inventory.Inventory
    • containsAtLeast

      public boolean containsAtLeast(org.bukkit.inventory.ItemStack item, int amount)
      Specified by:
      containsAtLeast in interface org.bukkit.inventory.Inventory
    • all

      @NotNull public @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack> all(@NotNull @NotNull org.bukkit.Material material)
      Specified by:
      all in interface org.bukkit.inventory.Inventory
    • all

      @NotNull public @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack> all(org.bukkit.inventory.ItemStack item)
      Specified by:
      all in interface org.bukkit.inventory.Inventory
    • first

      public int first(@NotNull @NotNull org.bukkit.Material material)
      Specified by:
      first in interface org.bukkit.inventory.Inventory
    • first

      public int first(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Specified by:
      first in interface org.bukkit.inventory.Inventory
    • firstEmpty

      public int firstEmpty()
      Specified by:
      firstEmpty in interface org.bukkit.inventory.Inventory
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface org.bukkit.inventory.Inventory
    • remove

      public void remove(@NotNull @NotNull org.bukkit.Material material)
      Specified by:
      remove in interface org.bukkit.inventory.Inventory
    • remove

      public void remove(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Specified by:
      remove in interface org.bukkit.inventory.Inventory
    • clear

      public void clear(int index)
      Specified by:
      clear in interface org.bukkit.inventory.Inventory
    • clear

      public void clear()
      Specified by:
      clear in interface org.bukkit.inventory.Inventory
    • close

      public int close()
      Specified by:
      close in interface org.bukkit.inventory.Inventory
    • consumeItem

      public int consumeItem(int slot, boolean wholeStack)
      Consumes an item or the full stack in the given slot.
      Parameters:
      slot - The slot to consume.
      wholeStack - True if we should remove the complete stack.
      Returns:
      The number of item really consumed.
    • consumeItem

      public int consumeItem(int slot)
      Consumes an item in the given slot.
      Parameters:
      slot - The slot to consume.
      Returns:
      The number of item really consumed.
    • getHolder

      public org.bukkit.inventory.InventoryHolder getHolder()
      The owner of this inventory.
      Specified by:
      getHolder in interface org.bukkit.inventory.Inventory
    • getType

      public org.bukkit.event.inventory.InventoryType getType()
      The type of this inventory.
      Specified by:
      getType in interface org.bukkit.inventory.Inventory
    • getTitle

      public String getTitle()
      The inventory's name.
    • getMaxStackSize

      public int getMaxStackSize()
      The inventory's maximum stack size.
      Specified by:
      getMaxStackSize in interface org.bukkit.inventory.Inventory
    • setMaxStackSize

      public void setMaxStackSize(int maxStackSize)
      The inventory's maximum stack size.
      Specified by:
      setMaxStackSize in interface org.bukkit.inventory.Inventory