Class PaginatedModal

java.lang.Object
io.rhythmknights.coreapi.component.modal.BaseModal
io.rhythmknights.coreapi.component.modal.PaginatedModal
All Implemented Interfaces:
org.bukkit.inventory.InventoryHolder
Direct Known Subclasses:
ScrollingModal

public class PaginatedModal extends BaseModal
Modal that allows you to have multiple pages
  • Constructor Details

    • PaginatedModal

      public PaginatedModal(@NotNull @NotNull ModalContainer modalContainer, int pageSize, @NotNull @NotNull Set<InteractionModifier> interactionModifiers)
    • PaginatedModal

      public PaginatedModal(@NotNull @NotNull ModalContainer modalContainer, @NotNull @NotNull PaginationRegion paginationRegion, @NotNull @NotNull Set<InteractionModifier> interactionModifiers)
      Constructor with pagination region
      Parameters:
      modalContainer - Modal container
      paginationRegion - Region for pagination items
      interactionModifiers - Interaction modifiers
  • Method Details

    • setPageSize

      public BaseModal setPageSize(int pageSize)
      Sets the page size
      Parameters:
      pageSize - The new page size
      Returns:
      The modal for easier use when declaring, works like a builder
    • setPaginationRegion

      public PaginatedModal setPaginationRegion(@NotNull @NotNull PaginationRegion paginationRegion)
      Sets the pagination region to use specific slots
      Parameters:
      paginationRegion - Region defining which slots to use for pagination
      Returns:
      The modal
    • getPaginationRegion

      public Optional<PaginationRegion> getPaginationRegion()
      Gets the pagination region if one is set
      Returns:
      Optional containing the pagination region, or empty if none set
    • setDynamicTitle

      public PaginatedModal setDynamicTitle(@NotNull @NotNull String baseTitle)
      Sets a dynamic title that updates with pagination
      Parameters:
      baseTitle - Base title text
      Returns:
      The modal
    • addItem

      public void addItem(@NotNull @NotNull ModalItem item)
      Adds an ModalItem to the next available slot in the page area
      Parameters:
      item - The ModalItem to add to the page
    • addItem

      public void addItem(@NotNull @NotNull ModalItem... items)
      Overridden BaseModal.addItem(ModalItem...) to add the items to the page instead
      Overrides:
      addItem in class BaseModal
      Parameters:
      items - Varargs for specifying the ModalItems
    • update

      public void update()
      Overridden BaseModal.update() to use the paginated open
      Overrides:
      update in class BaseModal
    • updatePageItem

      public void updatePageItem(int slot, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Updates the page ModalItem on the slot in the page Can get the slot from InventoryClickEvent.getSlot()
      Parameters:
      slot - The slot of the item to update
      itemStack - The new ItemStack
    • updatePageItem

      public void updatePageItem(int row, int col, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Alternative updatePageItem(int, ItemStack) that uses ROWS and COLUMNS instead
      Parameters:
      row - The row of the slot
      col - The columns of the slot
      itemStack - The new ItemStack
    • updatePageItem

      public void updatePageItem(int slot, @NotNull @NotNull ModalItem item)
      Alternative updatePageItem(int, ItemStack) that uses ModalItem instead
      Parameters:
      slot - The slot of the item to update
      item - The new ItemStack
    • updatePageItem

      public void updatePageItem(int row, int col, @NotNull @NotNull ModalItem item)
      Alternative updatePageItem(int, ModalItem) that uses ROWS and COLUMNS instead
      Parameters:
      row - The row of the slot
      col - The columns of the slot
      item - The new ModalItem
    • removePageItem

      public void removePageItem(@NotNull @NotNull ModalItem item)
      Removes a given ModalItem from the page.
      Parameters:
      item - The ModalItem to remove.
    • removePageItem

      public void removePageItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Removes a given ItemStack from the page.
      Parameters:
      item - The ItemStack to remove.
    • open

      public void open(@NotNull @NotNull org.bukkit.entity.HumanEntity player)
      Overrides BaseModal.open(HumanEntity) to use the paginated populator instead
      Overrides:
      open in class BaseModal
      Parameters:
      player - The HumanEntity to open the modal to
    • open

      public void open(@NotNull @NotNull org.bukkit.entity.HumanEntity player, int openPage)
      Specific open method for the Paginated modal Uses populatePage()
      Parameters:
      player - The HumanEntity to open it to
      openPage - The specific page to open at
    • updateTitle

      @NotNull public @NotNull BaseModal updateTitle(@NotNull @NotNull net.kyori.adventure.text.Component title)
      Overrides BaseModal.updateTitle(Component) to use the paginated populator instead Updates the title of the modal This method may cause LAG if used on a loop
      Overrides:
      updateTitle in class BaseModal
      Parameters:
      title - The title to set
      Returns:
      The modal for easier use when declaring, works like a builder
    • getCurrentPageItems

      @NotNull public @NotNull Map<@NotNull Integer,@NotNull ModalItem> getCurrentPageItems()
      Gets an immutable Map with all the current pages items
      Returns:
      The Map with all the currentPage
    • getPageItems

      @NotNull public @NotNull List<@NotNull ModalItem> getPageItems()
      Gets an immutable List with all the page items added to the modal
      Returns:
      The List with all the pageItems
    • getCurrentPageNum

      public int getCurrentPageNum()
      Gets the current page number
      Returns:
      The current page number
    • getNextPageNum

      public int getNextPageNum()
      Gets the next page number
      Returns:
      The next page number or pageNum if no next is present
    • getPrevPageNum

      public int getPrevPageNum()
      Gets the previous page number
      Returns:
      The previous page number or pageNum if no previous is present
    • next

      public boolean next()
      Goes to the next page
      Returns:
      False if there is no next page.
    • previous

      public boolean previous()
      Goes to the previous page if possible
      Returns:
      False if there is no previous page.
    • getPagesNum

      public int getPagesNum()
      Gets the number of pages the modal has
      Returns:
      The pages number
    • clearPageItems

      public void clearPageItems(boolean update)
      Clears all previously added page items
    • clearPageItems

      public void clearPageItems()
    • setPageNum

      public void setPageNum(int pageNum)
      Sets the page number
      Parameters:
      pageNum - Sets the current page to be the specified number