Class AbstractGuiComponent
java.lang.Object
io.github.toberocat.guiengine.components.AbstractGuiComponent
- All Implemented Interfaces:
GuiComponent
,GuiEvents
- Direct Known Subclasses:
EmbeddedGuiComponent
,SimpleItemComponent
,ToggleItemComponent
An abstract base class for GUI components.
This class provides common functionality for GUI components and implements the GuiComponent interface.
Created: 04/02/2023
Author: Tobias Madlberger (Tobias)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable GuiEngineApi
The api this component belongs toprotected final @NotNull List<GuiFunction>
The functions that will get called once a component has been clickedprotected final @NotNull List<GuiFunction>
The functions that will get called when a component's gui gets closedprotected @Nullable GuiContext
The context this component owns toprotected final @NotNull List<GuiFunction>
The functions that will get called once a component is part of a drag eventprotected final int
The height of this componentprotected final @NotNull String
protected int
X position of the componentprotected int
Y position of the componentprotected final @NotNull RenderPriority
The render priority of this component.protected final int
The width of this component -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractGuiComponent
(int offsetX, int offsetY, int width, int height, @NotNull RenderPriority priority, @NotNull String id, @NotNull List<GuiFunction> clickFunctions, @NotNull List<GuiFunction> dragFunctions, @NotNull List<GuiFunction> closeFunctions, boolean hidden) Constructor for AbstractGuiComponent. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clickedComponent
(@NotNull org.bukkit.event.inventory.InventoryClickEvent event) Called when a player clicks on a component in the GUI.void
closedComponent
(@NotNull org.bukkit.event.inventory.InventoryCloseEvent event) Called when a player closes the GUI.void
draggedComponent
(@NotNull org.bukkit.event.inventory.InventoryDragEvent event) Called when a player drags an item in the GUI.@NotNull List<GuiFunction>
Get the list of click functions for the GUI component.@NotNull List<GuiFunction>
Get the list of close functions for the GUI component.@NotNull List<GuiFunction>
Get the list of drag functions for the GUI component.@NotNull String
getId()
Get the ID of the GUI component.int
height()
Get the height of the GUI component.boolean
hidden()
Check if the GUI component is hidden.int
offsetX()
Get the X offset of the GUI component.int
offsetY()
Get the Y offset of the GUI component.@NotNull RenderPriority
Get the rendering priority of the GUI component.void
serialize
(@NotNull GeneratorContext gen, @NotNull com.fasterxml.jackson.databind.SerializerProvider serializers) Serialize the GUI component using the provided GeneratorContext and SerializerProvider.void
setApi
(@NotNull GuiEngineApi api) Set the GUI Engine API for the component.void
setContext
(@NotNull GuiContext context) Set the GUI context for the component.void
setHidden
(boolean hidden) Set the visibility of the GUI component.void
setOffsetX
(int x) Set the X offset of the GUI component.void
setOffsetY
(int y) Set the Y offset of the GUI component.int
width()
Get the width of the GUI component.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.toberocat.guiengine.components.GuiComponent
addActions, getType, isInComponent, render
Methods inherited from interface io.github.toberocat.guiengine.event.GuiEvents
onViewInit
-
Field Details
-
offsetX
protected int offsetXX position of the component -
offsetY
protected int offsetYY position of the component -
width
protected final int widthThe width of this component -
height
protected final int heightThe height of this component -
context
The context this component owns to -
api
The api this component belongs to -
priority
The render priority of this component. Determines the order of rendering nad the order of event receipation -
id
-
clickFunctions
The functions that will get called once a component has been clicked -
dragFunctions
The functions that will get called once a component is part of a drag event -
closeFunctions
The functions that will get called when a component's gui gets closed
-
-
Constructor Details
-
AbstractGuiComponent
protected AbstractGuiComponent(int offsetX, int offsetY, int width, int height, @NotNull @NotNull RenderPriority priority, @NotNull @NotNull String id, @NotNull @NotNull List<GuiFunction> clickFunctions, @NotNull @NotNull List<GuiFunction> dragFunctions, @NotNull @NotNull List<GuiFunction> closeFunctions, boolean hidden) Constructor for AbstractGuiComponent.- Parameters:
offsetX
- The X offset of the GUI component.offsetY
- The Y offset of the GUI component.width
- The width of the GUI component.height
- The height of the GUI component.priority
- The rendering priority of the GUI component.id
- The ID of the GUI component.clickFunctions
- The list of click functions for the GUI component.dragFunctions
- The list of drag functions for the GUI component.closeFunctions
- The list of close functions for the GUI component.hidden
- true if the GUI component is hidden, false otherwise.
-
-
Method Details
-
serialize
public void serialize(@NotNull @NotNull GeneratorContext gen, @NotNull @NotNull com.fasterxml.jackson.databind.SerializerProvider serializers) throws IOException Description copied from interface:GuiComponent
Serialize the GUI component using the provided GeneratorContext and SerializerProvider. This method is used to serialize the component's properties to a JSON representation.- Specified by:
serialize
in interfaceGuiComponent
- Parameters:
gen
- The GeneratorContext used for serialization.serializers
- The SerializerProvider used for serialization.- Throws:
IOException
- If there is an error during serialization.
-
clickedComponent
public void clickedComponent(@NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent event) Description copied from interface:GuiEvents
Called when a player clicks on a component in the GUI. The default behavior is to cancel the event and deny its result. If the action does not involve dropping an item, the event handling is skipped.- 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) Description copied from interface:GuiEvents
Called when a player drags an item in the GUI. The default behavior is to cancel the event.- 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) Description copied from interface:GuiEvents
Called when a player closes the GUI. The default behavior is to do nothing.- Specified by:
closedComponent
in interfaceGuiEvents
- Parameters:
event
- The `InventoryCloseEvent` representing the close event.
-
getId
Description copied from interface:GuiComponent
Get the ID of the GUI component.- Specified by:
getId
in interfaceGuiComponent
- Returns:
- The ID of the GUI component.
-
renderPriority
Description copied from interface:GuiComponent
Get the rendering priority of the GUI component. The rendering priority determines the order in which the component is rendered relative to other components.- Specified by:
renderPriority
in interfaceGuiComponent
- Returns:
- The rendering priority of the GUI component.
-
offsetX
public int offsetX()Description copied from interface:GuiComponent
Get the X offset of the GUI component. The X offset represents the horizontal position of the component within the GUI layout.- Specified by:
offsetX
in interfaceGuiComponent
- Returns:
- The X offset of the GUI component.
-
offsetY
public int offsetY()Description copied from interface:GuiComponent
Get the Y offset of the GUI component. The Y offset represents the vertical position of the component within the GUI layout.- Specified by:
offsetY
in interfaceGuiComponent
- Returns:
- The Y offset of the GUI component.
-
width
public int width()Description copied from interface:GuiComponent
Get the width of the GUI component.- Specified by:
width
in interfaceGuiComponent
- Returns:
- The width of the GUI component.
-
height
public int height()Description copied from interface:GuiComponent
Get the height of the GUI component.- Specified by:
height
in interfaceGuiComponent
- Returns:
- The height of the GUI component.
-
setOffsetX
public void setOffsetX(int x) Description copied from interface:GuiComponent
Set the X offset of the GUI component.- Specified by:
setOffsetX
in interfaceGuiComponent
- Parameters:
x
- The X offset to set.
-
setOffsetY
public void setOffsetY(int y) Description copied from interface:GuiComponent
Set the Y offset of the GUI component.- Specified by:
setOffsetY
in interfaceGuiComponent
- Parameters:
y
- The Y offset to set.
-
setHidden
public void setHidden(boolean hidden) Description copied from interface:GuiComponent
Set the visibility of the GUI component.- Specified by:
setHidden
in interfaceGuiComponent
- Parameters:
hidden
- true to hide the component, false to make it visible.
-
setApi
Description copied from interface:GuiComponent
Set the GUI Engine API for the component.- Specified by:
setApi
in interfaceGuiComponent
- Parameters:
api
- The GuiEngineApi to set.
-
setContext
Description copied from interface:GuiComponent
Set the GUI context for the component.- Specified by:
setContext
in interfaceGuiComponent
- Parameters:
context
- The GuiContext to set.
-
getClickFunctions
Get the list of click functions for the GUI component.- Returns:
- The list of click functions.
-
getDragFunctions
Get the list of drag functions for the GUI component.- Returns:
- The list of drag functions.
-
getCloseFunctions
Get the list of close functions for the GUI component.- Returns:
- The list of close functions.
-