Class DynamicGuiElement

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

public class DynamicGuiElement extends GuiElement
Represents an element in a gui that will query all it's data when drawn.
  • Constructor Details

    • DynamicGuiElement

      public DynamicGuiElement(char slotChar, Supplier<GuiElement> query)
      Represents an element in a gui that will query all it's data when drawn.
      Parameters:
      slotChar - The character to replace in the gui setup string
      query - Query the element data, this should return an element with the information
    • DynamicGuiElement

      public DynamicGuiElement(char slotChar, Function<org.bukkit.entity.HumanEntity,​GuiElement> query)
      Represents an element in a gui that will query all it's data when drawn.
      Parameters:
      slotChar - The character to replace in the gui setup string
      query - Query the element data, this should return an element with the information and handle null players properly
  • Method Details

    • update

      public void update()
      Query this element's state for every player who had it cached
    • update

      public DynamicGuiElement.CacheEntry update(org.bukkit.entity.HumanEntity player)
      Query this element's state for a certain player
      Parameters:
      player - The player for whom to update the 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
    • 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
    • getAction

      public GuiElement.Action getAction(org.bukkit.entity.HumanEntity who)
      Description copied from class: GuiElement
      Get the action that is executed when clicking on this element
      Overrides:
      getAction in class GuiElement
      Parameters:
      who - The player who views the page
      Returns:
      The action to run
    • getQuery

      public Function<org.bukkit.entity.HumanEntity,​GuiElement> getQuery()
      Get the supplier for this element's content
      Returns:
      The supplier query
    • setQuery

      public void setQuery(Function<org.bukkit.entity.HumanEntity,​GuiElement> query)
      Set the supplier for this element's content
      Parameters:
      query - The supplier query to set
    • queryElement

      public GuiElement queryElement(org.bukkit.entity.HumanEntity who)
      Query the element for a player
      Parameters:
      who - The player
      Returns:
      The GuiElement or null
    • getCachedElement

      public GuiElement getCachedElement(org.bukkit.entity.HumanEntity who)
      Get the cached element, creates a new one if there is none for that player. Use getLastCached(HumanEntity) to check if a player has something cached.
      Parameters:
      who - The player to get the element for
      Returns:
      The element that is currently cached
    • removeCachedElement

      public GuiElement removeCachedElement(org.bukkit.entity.HumanEntity who)
      Remove the cached element if the player has one.
      Parameters:
      who - The player to remove the cached element for
      Returns:
      The element that was cached or null if none was cached
    • getLastCached

      public long getLastCached(org.bukkit.entity.HumanEntity who)
      Get the time at which this element was last cached for a certain player
      Parameters:
      who - The player to get the last cache time for
      Returns:
      The timestamp from when it was last cached or -1 if it wasn't cached