Class GuiStateElement

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

public class GuiStateElement
extends GuiElement
An element that can switch between certain states. It automatically handles the switching of the item in the slot that corresponds to the state that the element is in.
  • Constructor Details

    • GuiStateElement

      public GuiStateElement​(char slotChar, int defaultState, GuiStateElement.State... states)
      An element that can switch between certain states.
      Parameters:
      slotChar - The character to replace in the gui setup string.
      defaultState - The index of the default state.
      states - The list of different GuiStateElement.States that this element can have.
    • GuiStateElement

      public GuiStateElement​(char slotChar, String defaultState, GuiStateElement.State... states)
      An element that can switch between certain states.
      Parameters:
      slotChar - The character to replace in the gui setup string.
      defaultState - The key of the default state.
      states - The list of different GuiStateElement.States that this element can have.
    • GuiStateElement

      public GuiStateElement​(char slotChar, Supplier<String> queryState, GuiStateElement.State... states)
      An element that can switch between certain states.
      Parameters:
      slotChar - The character to replace in the gui setup string.
      queryState - Supplier for the current state.
      states - The list of different GuiStateElement.States that this element can have.
    • GuiStateElement

      public GuiStateElement​(char slotChar, GuiStateElement.State... states)
      An element that can switch between certain states. The first state will be the default one.
      Parameters:
      slotChar - The character to replace in the gui setup string.
      states - The list of different GuiStateElement.States that this element can have.
  • Method Details

    • nextState

      public GuiStateElement.State nextState()
      Loop through the states of this element
      Returns:
      The new state (next one to the old)
    • previousState

      public GuiStateElement.State previousState()
      Loop through the states of this element backwards
      Returns:
      The new state (previous one to the old)
    • 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
    • setGui

      public void setGui​(InventoryGui gui)
      Description copied from class: GuiElement
      Set the gui this element belongs to
      Overrides:
      setGui in class GuiElement
      Parameters:
      gui - The GUI that this element is in
    • getState

      public GuiStateElement.State getState()
      Get the current state of this element
      Returns:
      The current state of this element
    • isSilent

      public boolean isSilent()
      Get whether or not this element should make a sound when interacted with
      Returns:
      Whether or not to make a sound when interacted with
    • setSilent

      public void setSilent​(boolean silent)
      Set whether or not this element should make a sound when interacted with
      Parameters:
      silent - Whether or not to make a sound when interacted with
    • setState

      public void setState​(String key) throws IllegalArgumentException
      Set the current state with the state's key. Does not trigger the state's change.
      Parameters:
      key - The key to search for.
      Throws:
      IllegalArgumentException - Thrown if there is no state with the provided key.