Class GuiStorageElement

java.lang.Object
de.themoep.inventorygui.GuiElement
de.themoep.inventorygui.GuiStorageElement

public class GuiStorageElement
extends GuiElement
This element is used to access an Inventory. The slots in the inventory are selected by searching through the whole gui the element is in and getting the number of the spot in the character group that this element is in.
E.g. if you have five characters called "s" in the gui setup and the second element is accessed by the player then it will translate to the second slot in the inventory.
  • Constructor Details

    • GuiStorageElement

      public GuiStorageElement​(char slotChar, org.bukkit.inventory.Inventory storage)
      An element used to access an Inventory.
      Parameters:
      slotChar - The character to replace in the gui setup string.
      storage - The Inventory that this element is linked to.
    • GuiStorageElement

      public GuiStorageElement​(char slotChar, org.bukkit.inventory.Inventory storage, int invSlot)
      An element used to access a specific slot in an Inventory.
      Parameters:
      slotChar - The character to replace in the gui setup string.
      storage - The Inventory that this element is linked to.
      invSlot - The index of the slot to access in the Inventory.
    • GuiStorageElement

      public GuiStorageElement​(char slotChar, org.bukkit.inventory.Inventory storage, int invSlot, Runnable applyStorage, Function<GuiStorageElement.ValidatorInfo,​Boolean> itemValidator)
      An element used to access a specific slot in an Inventory.
      Parameters:
      slotChar - The character to replace in the gui setup string.
      storage - The Inventory that this element is linked to.
      invSlot - The index of the slot to access in the Inventory.
      applyStorage - Apply the storage that this element represents.
      itemValidator - Should return false for items that should not work in that slot Can be null if the storage is directly linked.
  • Method Details

    • getItem

      public org.bukkit.inventory.ItemStack getItem​(org.bukkit.entity.HumanEntity who, int slot)
      Description copied from class: GuiElement
      Get the item that is displayed by this element on a certain page
      Specified by:
      getItem in class GuiElement
      Parameters:
      who - The player who views the page
      slot - The slot to get the item for
      Returns:
      The ItemStack that is displayed as this element
    • getStorage

      public org.bukkit.inventory.Inventory getStorage()
      Get the Inventory that this element is linked to.
      Returns:
      The Inventory that this element is linked to.
    • getStorageItem

      public org.bukkit.inventory.ItemStack getStorageItem​(int slot)
      Get the item in the storage that corresponds to the InventoryGui slot
      Parameters:
      slot - The slot in the GUI
      Returns:
      The ItemStack or null if the slot is outside of the item's size
    • setStorageItem

      public boolean setStorageItem​(int slot, org.bukkit.inventory.ItemStack item)
      Set the item in the storage that corresponds to the InventoryGui slot.
      Parameters:
      slot - The slot in the GUI
      item - The ItemStack to set
      Returns:
      true if the item was set; false if the slot was outside of this storage
    • getApplyStorage

      public Runnable getApplyStorage()
      Get the runnable that applies the storage
      Returns:
      The storage applying runnable; might be null
    • setApplyStorage

      public void setApplyStorage​(Runnable applyStorage)
      Set what should be done to apply the storage. Not necessary if the storage is directly backed by a real inventory.
      Parameters:
      applyStorage - How to apply the storage; can be null if nothing should be done
    • getItemValidator

      public Function<GuiStorageElement.ValidatorInfo,​Boolean> getItemValidator()
      Get the item validator
      Returns:
      The item validator
    • setItemValidator

      public void setItemValidator​(Function<GuiStorageElement.ValidatorInfo,​Boolean> itemValidator)
      Set a function that can validate whether or not an item can fit in the slot
      Parameters:
      itemValidator - The item validator that takes a GuiStorageElement.ValidatorInfo and returns true for items that should and false for items that should not work in that slot
    • validateItem

      public boolean validateItem​(int slot, org.bukkit.inventory.ItemStack item)
      Validate whether or not an item can be put in a slot with the item validator set in setItemValidator(Function)
      Parameters:
      slot - The slot the item should be tested for
      item - The item to test
      Returns:
      true for items that should and false for items that should not work in that slot