Class GuiElement

java.lang.Object
de.themoep.inventorygui.GuiElement
Direct Known Subclasses:
DynamicGuiElement, GuiElementGroup, GuiStateElement, GuiStorageElement, StaticGuiElement

public abstract class GuiElement
extends Object
Represents an element in a gui
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static interface  GuiElement.Action  
    static class  GuiElement.Click  
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected InventoryGui gui  
    protected int[] slots  
  • Constructor Summary

    Constructors 
    Constructor Description
    GuiElement​(char slotChar)
    Represents an element in a gui that doesn't have any action when clicked
    GuiElement​(char slotChar, GuiElement.Action action)
    Represents an element in a gui
  • Method Summary

    Modifier and Type Method Description
    GuiElement.Action getAction​(org.bukkit.entity.HumanEntity who)
    Get the action that is executed when clicking on this element
    abstract org.bukkit.inventory.ItemStack getItem​(org.bukkit.entity.HumanEntity who, int slot)
    Get the item that is displayed by this element on a certain page
    char getSlotChar()
    Get the character in the gui setup that corresponds with this element
    int getSlotIndex​(int slot)
    Get the index that this slot has in the list of slots that this element is displayed in
    int getSlotIndex​(int slot, int pageNumber)
    Get the index that this slot has in the list of slots that this element is displayed in
    int[] getSlots()
    Get the indexes of the lots that this element is displayed in
    void setAction​(GuiElement.Action action)
    Set the action that is executed when clicking on this element
    void setGui​(InventoryGui gui)
    Set the gui this element belongs to
    void setSlots​(int[] slots)
    Set the ids of the slots where this element is assigned to

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • GuiElement

      public GuiElement​(char slotChar, GuiElement.Action action)
      Represents an element in a gui
      Parameters:
      slotChar - The character to replace in the gui setup string
      action - The action to run when the player clicks on this element
    • GuiElement

      public GuiElement​(char slotChar)
      Represents an element in a gui that doesn't have any action when clicked
      Parameters:
      slotChar - The character to replace in the gui setup string
  • Method Details

    • getSlotChar

      public char getSlotChar()
      Get the character in the gui setup that corresponds with this element
      Returns:
      The character
    • getItem

      public abstract org.bukkit.inventory.ItemStack getItem​(org.bukkit.entity.HumanEntity who, int slot)
      Get the item that is displayed by this element on a certain page
      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
    • getAction

      public GuiElement.Action getAction​(org.bukkit.entity.HumanEntity who)
      Get the action that is executed when clicking on this element
      Parameters:
      who - The player who views the page
      Returns:
      The action to run
    • setAction

      public void setAction​(GuiElement.Action action)
      Set the action that is executed when clicking on this element
      Parameters:
      action - The action to run. The GuiElement.Action.onClick(de.themoep.inventorygui.GuiElement.Click) method should return whether or not the click event should be cancelled
    • getSlots

      public int[] getSlots()
      Get the indexes of the lots that this element is displayed in
      Returns:
      An array of the lost indexes
    • setSlots

      public void setSlots​(int[] slots)
      Set the ids of the slots where this element is assigned to
      Parameters:
      slots - An array of the slot ids where this element is displayed
    • getSlotIndex

      public int getSlotIndex​(int slot)
      Get the index that this slot has in the list of slots that this element is displayed in
      Parameters:
      slot - The id of the slot
      Returns:
      The index in the list of slots that this id has or -1 if it isn't in that list
    • getSlotIndex

      public int getSlotIndex​(int slot, int pageNumber)
      Get the index that this slot has in the list of slots that this element is displayed in
      Parameters:
      slot - The id of the slot
      pageNumber - The number of the page that the gui is on
      Returns:
      The index in the list of slots that this id has or -1 if it isn't in that list
    • setGui

      public void setGui​(InventoryGui gui)
      Set the gui this element belongs to
      Parameters:
      gui - The GUI that this element is in