Class AbstractGuiComponent

java.lang.Object
io.github.toberocat.guiengine.components.AbstractGuiComponent
All Implemented Interfaces:
GuiComponent, GuiEvents
Direct Known Subclasses:
EmbeddedGuiComponent, SimpleItemComponent, ToggleItemComponent

public abstract class AbstractGuiComponent extends Object implements GuiComponent
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 Details

    • offsetX

      protected int offsetX
      X position of the component
    • offsetY

      protected int offsetY
      Y position of the component
    • width

      protected final int width
      The width of this component
    • height

      protected final int height
      The height of this component
    • context

      @Nullable protected @Nullable GuiContext context
      The context this component owns to
    • api

      @Nullable protected @Nullable GuiEngineApi api
      The api this component belongs to
    • priority

      @NotNull protected final @NotNull RenderPriority priority
      The render priority of this component. Determines the order of rendering nad the order of event receipation
    • id

      @NotNull protected final @NotNull String id
    • clickFunctions

      @NotNull protected final @NotNull List<GuiFunction> clickFunctions
      The functions that will get called once a component has been clicked
    • dragFunctions

      @NotNull protected final @NotNull List<GuiFunction> dragFunctions
      The functions that will get called once a component is part of a drag event
    • closeFunctions

      @NotNull protected final @NotNull List<GuiFunction> 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 interface GuiComponent
      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 interface GuiEvents
      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 interface GuiEvents
      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 interface GuiEvents
      Parameters:
      event - The `InventoryCloseEvent` representing the close event.
    • getId

      @NotNull public @NotNull String getId()
      Description copied from interface: GuiComponent
      Get the ID of the GUI component.
      Specified by:
      getId in interface GuiComponent
      Returns:
      The ID of the GUI component.
    • renderPriority

      @NotNull public @NotNull RenderPriority 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 interface GuiComponent
      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 interface GuiComponent
      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 interface GuiComponent
      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 interface GuiComponent
      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 interface GuiComponent
      Returns:
      The height of the GUI component.
    • hidden

      public boolean hidden()
      Description copied from interface: GuiComponent
      Check if the GUI component is hidden.
      Specified by:
      hidden in interface GuiComponent
      Returns:
      true if the component is hidden, false otherwise.
    • setOffsetX

      public void setOffsetX(int x)
      Description copied from interface: GuiComponent
      Set the X offset of the GUI component.
      Specified by:
      setOffsetX in interface GuiComponent
      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 interface GuiComponent
      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 interface GuiComponent
      Parameters:
      hidden - true to hide the component, false to make it visible.
    • setApi

      public void setApi(@NotNull @NotNull GuiEngineApi api)
      Description copied from interface: GuiComponent
      Set the GUI Engine API for the component.
      Specified by:
      setApi in interface GuiComponent
      Parameters:
      api - The GuiEngineApi to set.
    • setContext

      public void setContext(@NotNull @NotNull GuiContext context)
      Description copied from interface: GuiComponent
      Set the GUI context for the component.
      Specified by:
      setContext in interface GuiComponent
      Parameters:
      context - The GuiContext to set.
    • getClickFunctions

      @NotNull public @NotNull List<GuiFunction> getClickFunctions()
      Get the list of click functions for the GUI component.
      Returns:
      The list of click functions.
    • getDragFunctions

      @NotNull public @NotNull List<GuiFunction> getDragFunctions()
      Get the list of drag functions for the GUI component.
      Returns:
      The list of drag functions.
    • getCloseFunctions

      @NotNull public @NotNull List<GuiFunction> getCloseFunctions()
      Get the list of close functions for the GUI component.
      Returns:
      The list of close functions.