Class GuiContext
java.lang.Object
io.github.toberocat.guiengine.context.GuiContext
- All Implemented Interfaces:
GuiEventListener
,GuiEvents
The `GuiContext` class represents a GUI context that holds information about the GUI components and actions for a
specific player.
This class is licensed under the GNU General Public License.
- Since:
- 04/02/2023
- Author:
- Tobias Madlberger (Tobias)
-
Constructor Summary
ConstructorsConstructorDescriptionGuiContext
(@NotNull GuiInterpreter interpreter, @NotNull String title, int width, int height) Constructs a new `GuiContext` with the provided interpreter, title, width, and height. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(@NotNull GuiEngineApi api, @NotNull GuiComponent component) Adds a GUI component to this context.void
add
(@NotNull GuiEngineApi api, @NotNull XmlComponent component) Adds an XML component to this context.void
add
(@NotNull GuiEngineApi api, @NotNull XmlComponent @NotNull ... components) Adds multiple XML components to this context.void
clickedComponent
(@NotNull org.bukkit.event.inventory.InventoryClickEvent event) Handles the event when a player clicks on a component in the GUI.void
closedComponent
(@NotNull org.bukkit.event.inventory.InventoryCloseEvent event) Handles the event when a player closes the GUI.@NotNull List<GuiComponent>
Returns the list of GUI components in this context.@NotNull Stream<GuiComponent>
Returns a stream of GUI components in ascending order of their render priority.@NotNull Stream<GuiComponent>
Returns a stream of GUI components in descending order of their render priority.void
draggedComponent
(@NotNull org.bukkit.event.inventory.InventoryDragEvent event) Handles the event when a player drags an item in the GUI.void
editXmlComponentById
(@NotNull GuiEngineApi api, @NotNull String id, @NotNull Consumer<XmlComponent> editCallback) Edits an XML component by ID with the specified edit callback.boolean
Checks if this `GuiContext` is equal to another object.@Nullable GuiComponent
findComponentById
(@NotNull String id) Finds a GUI component with the specified ID.<T extends GuiComponent>
TfindComponentById
(@NotNull String id, @NotNull Class<T> clazz) Finds a GUI component with the specified ID and class type.@NotNull GuiContext
Returns the current `GuiContext`.@NotNull UUID
Returns the unique identifier of this `GuiContext`.@NotNull Set<io.github.toberocat.toberocore.action.Action>
Returns the set of local actions associated with this context.int
hashCode()
Generates the hash code for this `GuiContext`.int
height()
Returns the height of the GUI context.@NotNull GuiInterpreter
Returns the associated `GuiInterpreter` for this context.@Nullable org.bukkit.inventory.Inventory
Returns the inventory associated with this GUI context.void
removeById
(@NotNull String id) Removes a GUI component with the specified ID.void
render()
Renders the GUI context by updating the inventory with the components' content.void
setInventory
(@Nullable org.bukkit.inventory.Inventory inventory) Sets the inventory for this GUI context.void
setViewer
(@Nullable org.bukkit.entity.Player viewer) Sets the viewer (player) for this GUI context.@NotNull String
title()
Returns the title of the GUI context.toString()
Converts this `GuiContext` object to a human-readable string representation.@Nullable org.bukkit.entity.Player
viewer()
Returns the viewer (player) associated with this GUI context.int
width()
Returns the width of the GUI context.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.github.toberocat.guiengine.event.GuiEventListener
listen
Methods inherited from interface io.github.toberocat.guiengine.event.GuiEvents
onViewInit
-
Constructor Details
-
GuiContext
public GuiContext(@NotNull @NotNull GuiInterpreter interpreter, @NotNull @NotNull String title, int width, int height) Constructs a new `GuiContext` with the provided interpreter, title, width, and height.- Parameters:
interpreter
- The `GuiInterpreter` associated with this context.title
- The title of the GUI context.width
- The width of the GUI context.height
- The height of the GUI context.
-
-
Method Details
-
componentsAscending
Returns a stream of GUI components in ascending order of their render priority.- Returns:
- A stream of GUI components in ascending order of their render priority.
-
componentsDescending
Returns a stream of GUI components in descending order of their render priority.- Returns:
- A stream of GUI components in descending order of their render priority.
-
findComponentById
Finds a GUI component with the specified ID.- Parameters:
id
- The ID of the GUI component to find.- Returns:
- The GUI component with the specified ID, or null if not found.
-
findComponentById
@Nullable public <T extends GuiComponent> T findComponentById(@NotNull @NotNull String id, @NotNull @NotNull Class<T> clazz) Finds a GUI component with the specified ID and class type.- Type Parameters:
T
- The type of the GUI component.- Parameters:
id
- The ID of the GUI component to find.clazz
- The class type of the GUI component.- Returns:
- The GUI component with the specified ID and class type, or null if not found or the class type does not match.
-
removeById
Removes a GUI component with the specified ID.- Parameters:
id
- The ID of the GUI component to remove.
-
editXmlComponentById
public void editXmlComponentById(@NotNull @NotNull GuiEngineApi api, @NotNull @NotNull String id, @NotNull @NotNull Consumer<XmlComponent> editCallback) Edits an XML component by ID with the specified edit callback.- Parameters:
api
- The `GuiEngineApi` associated with the XML component.id
- The ID of the XML component to edit.editCallback
- The callback function to edit the XML component.
-
add
Adds a GUI component to this context.- Parameters:
api
- The `GuiEngineApi` associated with the GUI component.component
- The GUI component to add.
-
add
Adds an XML component to this context.- Parameters:
api
- The `GuiEngineApi` associated with the XML component.component
- The XML component to add.
-
add
public void add(@NotNull @NotNull GuiEngineApi api, @NotNull @NotNull XmlComponent @NotNull ... components) Adds multiple XML components to this context.- Parameters:
api
- The `GuiEngineApi` associated with the XML components.components
- The XML components to add.
-
clickedComponent
public void clickedComponent(@NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent event) Handles the event when a player clicks on a component in the GUI.- Specified by:
clickedComponent
in interfaceGuiEvents
- Parameters:
event
- The `InventoryClickEvent` representing the click event.
-
draggedComponent
public void draggedComponent(@NotNull @NotNull org.bukkit.event.inventory.InventoryDragEvent event) Handles the event when a player drags an item in the GUI.- Specified by:
draggedComponent
in interfaceGuiEvents
- Parameters:
event
- The `InventoryDragEvent` representing the drag event.
-
closedComponent
public void closedComponent(@NotNull @NotNull org.bukkit.event.inventory.InventoryCloseEvent event) Handles the event when a player closes the GUI.- Specified by:
closedComponent
in interfaceGuiEvents
- Parameters:
event
- The `InventoryCloseEvent` representing the close event.
-
interpreter
Returns the associated `GuiInterpreter` for this context.- Returns:
- The associated `GuiInterpreter`.
-
title
Returns the title of the GUI context.- Returns:
- The title of the GUI context.
-
width
public int width()Returns the width of the GUI context.- Returns:
- The width of the GUI context.
-
height
public int height()Returns the height of the GUI context.- Returns:
- The height of the GUI context.
-
components
Returns the list of GUI components in this context.- Returns:
- The list of GUI components.
-
getLocalActions
Returns the set of local actions associated with this context.- Returns:
- The set of local actions.
-
viewer
@Nullable public @Nullable org.bukkit.entity.Player viewer()Returns the viewer (player) associated with this GUI context.- Returns:
- The viewer (player).
-
inventory
@Nullable public @Nullable org.bukkit.inventory.Inventory inventory()Returns the inventory associated with this GUI context.- Returns:
- The inventory.
-
setInventory
public void setInventory(@Nullable @Nullable org.bukkit.inventory.Inventory inventory) Sets the inventory for this GUI context.- Parameters:
inventory
- The inventory to set.
-
setViewer
public void setViewer(@Nullable @Nullable org.bukkit.entity.Player viewer) Sets the viewer (player) for this GUI context.- Parameters:
viewer
- The viewer (player) to set.
-
render
public void render()Renders the GUI context by updating the inventory with the components' content. -
equals
Checks if this `GuiContext` is equal to another object. -
hashCode
public int hashCode()Generates the hash code for this `GuiContext`. -
toString
Converts this `GuiContext` object to a human-readable string representation. -
getContextId
Returns the unique identifier of this `GuiContext`.- Returns:
- The unique identifier.
-
getContext
Returns the current `GuiContext`.- Specified by:
getContext
in interfaceGuiEventListener
- Returns:
- The current `GuiContext`.
-