All Implemented Interfaces:
ContextContainer, GuiComponent, GuiComponentContainer, GuiEvents

public class PagedComponent extends EmbeddedGuiComponent implements GuiComponentContainer, ContextContainer
A custom GUI component that represents a paged GUI. It allows displaying multiple pages of components in a specific pattern on a GUI. This component can be navigated using NextPageAction and PreviousPageAction actions.

Created: 30.04.2023

Author:
Tobias Madlberger (Tobias)
  • Field Details

    • TYPE

      public static final String TYPE
      See Also:
    • parent

      @NotNull protected final @NotNull ParserContext parent
    • pattern

      protected final int[] pattern
    • showingPage

      protected int showingPage
  • Constructor Details

    • PagedComponent

      public PagedComponent(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, @NotNull @NotNull String targetGui, boolean copyAir, boolean interactions, @NotNull @NotNull ParserContext parent, int[] pattern, int showingPage)
      Constructs a new PagedComponent instance with the specified parameters.
      Parameters:
      offsetX - The X-axis offset of the component within the GUI.
      offsetY - The Y-axis offset of the component within the GUI.
      width - The width of the component.
      height - The height of the component.
      priority - The rendering priority of the component.
      id - The unique ID of the component.
      clickFunctions - The list of click functions associated with the component.
      dragFunctions - The list of drag functions associated with the component.
      closeFunctions - The list of close functions associated with the component.
      hidden - Whether the component is hidden or not.
      targetGui - The target GUI to display when this component is clicked.
      copyAir - Whether to copy air items to the target GUI.
      interactions - Whether to enable interactions between this component and the target GUI.
      parent - The parent parser context that contains the GUI definition.
      pattern - The pattern of slots on the GUI to arrange the components.
      showingPage - The index of the currently showing page.
  • 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
      Overrides:
      serialize in class EmbeddedGuiComponent
      Parameters:
      gen - The GeneratorContext used for serialization.
      serializers - The SerializerProvider used for serialization.
      Throws:
      IOException - If there is an error during serialization.
    • onViewInit

      public void onViewInit(@NotNull @NotNull Map<String,String> placeholders)
      Description copied from interface: GuiEvents
      Called when the GUI is initialized and the viewer (player) opens it. This method is intended to handle any necessary initialization tasks before the GUI is shown to the player. The `placeholders` parameter can be used to store additional information specific to the GUI. The default behavior is to do nothing.
      Specified by:
      onViewInit in interface GuiEvents
      Overrides:
      onViewInit in class EmbeddedGuiComponent
      Parameters:
      placeholders - A map containing placeholder data for the GUI.
    • addPage

      public void addPage(@NotNull @NotNull GuiContext page)
      Adds a new page to the paged component.
      Parameters:
      page - The new page to add.
    • addPage

      public void addPage(@NotNull @NotNull GuiContext page, int position)
      Adds a new page to the paged component at the specified position.
      Parameters:
      page - The new page to add.
      position - The position at which to add the page.
    • addComponent

      public void addComponent(@NotNull @NotNull GuiComponent component)
      Adds a new component to the current page.
      Specified by:
      addComponent in interface GuiComponentContainer
      Parameters:
      component - The component to add.
    • clearContainer

      public void clearContainer()
      Specified by:
      clearContainer in interface ContextContainer
      Specified by:
      clearContainer in interface GuiComponentContainer
    • addContext

      public void addContext(GuiContext context)
      Specified by:
      addContext in interface ContextContainer
    • getType

      @NotNull public @NotNull String getType()
      Description copied from interface: GuiComponent
      Get the type of the GUI component.
      Specified by:
      getType in interface GuiComponent
      Overrides:
      getType in class EmbeddedGuiComponent
      Returns:
      The type of the GUI component.
    • render

      public void render(@NotNull @NotNull org.bukkit.entity.Player viewer, @NotNull @NotNull org.bukkit.inventory.ItemStack[][] buffer)
      Description copied from interface: GuiComponent
      Render the GUI component for a specific player and inventory configuration. This method is responsible for rendering the component to the graphical user interface.
      Specified by:
      render in interface GuiComponent
      Overrides:
      render in class EmbeddedGuiComponent
      Parameters:
      viewer - The player for whom the component should be rendered.
      buffer - The inventory configuration used for rendering the GUI.
    • addActions

      public void addActions(@NotNull @NotNull Set<io.github.toberocat.toberocore.action.Action> actions)
      Description copied from interface: GuiComponent
      Add actions to the GUI component. This method allows adding GUI actions that can be triggered by the player interacting with the component.
      Specified by:
      addActions in interface GuiComponent
      Parameters:
      actions - A set of actions to be added to the component.
    • setShowingPage

      public void setShowingPage(int page)
      Sets the currently showing page index of the paged component.
      Parameters:
      page - The index of the page to show.
      Throws:
      IllegalArgumentException - If the specified page is not within the valid bounds.
    • getShowingPage

      public int getShowingPage()
      Gets the index of the currently showing page of the paged component.
      Returns:
      The index of the currently showing page.
    • getPage

      public int getPage()
      Gets the current page number of the paged component.
      Returns:
      The current page number (1-based index).
    • getAvailablePages

      public int getAvailablePages()
      Gets the total number of available pages in the paged component.
      Returns:
      The total number of available pages.
    • addEmptyPage

      public void addEmptyPage()
      Creates a new empty page
    • resetPatternOnPage

      public void resetPatternOnPage()
      Resets the pattern. This will break stuff with the automated paging if used wrong