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 GuiEngineApiThe 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 GuiContextThe 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 intThe height of this componentprotected final @NotNull Stringprotected intX position of the componentprotected intY position of the componentprotected final @NotNull RenderPriorityThe render priority of this component.protected final intThe width of this component -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractGuiComponent(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 TypeMethodDescriptionvoidclickedComponent(@NotNull org.bukkit.event.inventory.InventoryClickEvent event) Called when a player clicks on a component in the GUI.voidclosedComponent(@NotNull org.bukkit.event.inventory.InventoryCloseEvent event) Called when a player closes the GUI.voiddraggedComponent(@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 StringgetId()Get the ID of the GUI component.intheight()Get the height of the GUI component.booleanhidden()Check if the GUI component is hidden.intoffsetX()Get the X offset of the GUI component.intoffsetY()Get the Y offset of the GUI component.@NotNull RenderPriorityGet the rendering priority of the GUI component.voidserialize(@NotNull GeneratorContext gen, @NotNull com.fasterxml.jackson.databind.SerializerProvider serializers) Serialize the GUI component using the provided GeneratorContext and SerializerProvider.voidsetApi(@NotNull GuiEngineApi api) Set the GUI Engine API for the component.voidsetContext(@NotNull GuiContext context) Set the GUI context for the component.voidsetHidden(boolean hidden) Set the visibility of the GUI component.voidsetOffsetX(int x) Set the X offset of the GUI component.voidsetOffsetY(int y) Set the Y offset of the GUI component.intwidth()Get the width of the GUI component.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.toberocat.guiengine.components.GuiComponent
addActions, getType, isInComponent, renderMethods 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:GuiComponentSerialize 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:
serializein 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:GuiEventsCalled 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:
clickedComponentin 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:GuiEventsCalled when a player drags an item in the GUI. The default behavior is to cancel the event.- Specified by:
draggedComponentin 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:GuiEventsCalled when a player closes the GUI. The default behavior is to do nothing.- Specified by:
closedComponentin interfaceGuiEvents- Parameters:
event- The `InventoryCloseEvent` representing the close event.
-
getId
Description copied from interface:GuiComponentGet the ID of the GUI component.- Specified by:
getIdin interfaceGuiComponent- Returns:
- The ID of the GUI component.
-
renderPriority
Description copied from interface:GuiComponentGet 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:
renderPriorityin interfaceGuiComponent- Returns:
- The rendering priority of the GUI component.
-
offsetX
public int offsetX()Description copied from interface:GuiComponentGet the X offset of the GUI component. The X offset represents the horizontal position of the component within the GUI layout.- Specified by:
offsetXin interfaceGuiComponent- Returns:
- The X offset of the GUI component.
-
offsetY
public int offsetY()Description copied from interface:GuiComponentGet the Y offset of the GUI component. The Y offset represents the vertical position of the component within the GUI layout.- Specified by:
offsetYin interfaceGuiComponent- Returns:
- The Y offset of the GUI component.
-
width
public int width()Description copied from interface:GuiComponentGet the width of the GUI component.- Specified by:
widthin interfaceGuiComponent- Returns:
- The width of the GUI component.
-
height
public int height()Description copied from interface:GuiComponentGet the height of the GUI component.- Specified by:
heightin interfaceGuiComponent- Returns:
- The height of the GUI component.
-
setOffsetX
public void setOffsetX(int x) Description copied from interface:GuiComponentSet the X offset of the GUI component.- Specified by:
setOffsetXin interfaceGuiComponent- Parameters:
x- The X offset to set.
-
setOffsetY
public void setOffsetY(int y) Description copied from interface:GuiComponentSet the Y offset of the GUI component.- Specified by:
setOffsetYin interfaceGuiComponent- Parameters:
y- The Y offset to set.
-
setHidden
public void setHidden(boolean hidden) Description copied from interface:GuiComponentSet the visibility of the GUI component.- Specified by:
setHiddenin interfaceGuiComponent- Parameters:
hidden- true to hide the component, false to make it visible.
-
setApi
Description copied from interface:GuiComponentSet the GUI Engine API for the component.- Specified by:
setApiin interfaceGuiComponent- Parameters:
api- The GuiEngineApi to set.
-
setContext
Description copied from interface:GuiComponentSet the GUI context for the component.- Specified by:
setContextin 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.
-