Package de.themoep.inventorygui
Class DynamicGuiElement
java.lang.Object
de.themoep.inventorygui.GuiElement
de.themoep.inventorygui.DynamicGuiElement
Represents an element in a gui that will query all it's data when drawn.
-
Nested Class Summary
Nested classes/interfaces inherited from class de.themoep.inventorygui.GuiElement
GuiElement.Action, GuiElement.Click
-
Field Summary
Fields inherited from class de.themoep.inventorygui.GuiElement
gui, slots
-
Constructor Summary
ConstructorDescriptionDynamicGuiElement
(char slotChar, Function<org.bukkit.entity.HumanEntity, GuiElement> query) Represents an element in a gui that will query all it's data when drawn.DynamicGuiElement
(char slotChar, Supplier<GuiElement> query) Represents an element in a gui that will query all it's data when drawn. -
Method Summary
Modifier and TypeMethodDescriptiongetAction
(org.bukkit.entity.HumanEntity who) Get the action that is executed when clicking on this elementgetCachedElement
(org.bukkit.entity.HumanEntity who) Get the cached element, creates a new one if there is none for that player.org.bukkit.inventory.ItemStack
getItem
(org.bukkit.entity.HumanEntity who, int slot) Get the item that is displayed by this element on a certain pagelong
getLastCached
(org.bukkit.entity.HumanEntity who) Get the time at which this element was last cached for a certain playerFunction
<org.bukkit.entity.HumanEntity, GuiElement> getQuery()
Get the supplier for this element's contentqueryElement
(org.bukkit.entity.HumanEntity who) Query the element for a playerremoveCachedElement
(org.bukkit.entity.HumanEntity who) Remove the cached element if the player has one.void
setGui
(InventoryGui gui) Set the gui this element belongs tovoid
setQuery
(Function<org.bukkit.entity.HumanEntity, GuiElement> query) Set the supplier for this element's contentvoid
update()
Query this element's state for every player who had it cachedupdate
(org.bukkit.entity.HumanEntity player) Query this element's state for a certain playerMethods inherited from class de.themoep.inventorygui.GuiElement
getGui, getSlotChar, getSlotIndex, getSlotIndex, getSlots, setAction, setSlots
-
Constructor Details
-
DynamicGuiElement
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 stringquery
- Query the element data, this should return an element with the information
-
DynamicGuiElement
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 stringquery
- 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
Query this element's state for a certain player- Parameters:
player
- The player for whom to update the element
-
setGui
Description copied from class:GuiElement
Set the gui this element belongs to- Overrides:
setGui
in classGuiElement
- 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 classGuiElement
- Parameters:
who
- The player who views the pageslot
- The slot to get the item for- Returns:
- The ItemStack that is displayed as this element
-
getAction
Description copied from class:GuiElement
Get the action that is executed when clicking on this element- Overrides:
getAction
in classGuiElement
- Parameters:
who
- The player who views the page- Returns:
- The action to run
-
getQuery
Get the supplier for this element's content- Returns:
- The supplier query
-
setQuery
Set the supplier for this element's content- Parameters:
query
- The supplier query to set
-
queryElement
Query the element for a player- Parameters:
who
- The player- Returns:
- The GuiElement or null
-
getCachedElement
Get the cached element, creates a new one if there is none for that player. UsegetLastCached(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
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
-