Class PaginationMenu

java.lang.Object
me.tayebyassine.homestead.gui.PaginationMenu
All Implemented Interfaces:
org.bukkit.event.Listener

public class PaginationMenu extends Object implements org.bukkit.event.Listener
Paginated menu class with page navigation support.

Supports next/previous page buttons, item-based content with automatic page slicing, action buttons in the bottom row, and dynamic slot replacement. Handles page overflow and empty slot filling automatically. Registers itself as a Bukkit Listener on construction and unregisters on close.

  • Method Details

    • builder

      public static PaginationMenu.Builder builder(String menuKey, int size)
      Creates a new PaginationMenu.Builder for the given menu key and inventory size.
      Parameters:
      menuKey - the menu title key
      size - the inventory size (must be a multiple of 9, at least 36)
      Returns:
      a new Builder instance
    • builder

      public static PaginationMenu.Builder builder(String menuKey, Placeholder titlePlaceholder, int size)
      Creates a new PaginationMenu.Builder with a placeholder for the menu title.
      Parameters:
      menuKey - the menu title key
      titlePlaceholder - the placeholder to apply to the title
      size - the inventory size (must be a multiple of 9, at least 36)
      Returns:
      a new Builder instance
    • addActionButton

      public PaginationMenu addActionButton(int index, org.bukkit.inventory.ItemStack item, BiConsumer<org.bukkit.entity.Player, org.bukkit.event.inventory.InventoryClickEvent> callback)
      Adds an action button to the bottom row of the menu.
      Parameters:
      index - the button index (0, 1, or 2)
      item - the item to display
      callback - the click callback
      Returns:
      this menu instance
    • replaceSlot

      public PaginationMenu replaceSlot(int index, org.bukkit.inventory.ItemStack newItem)
      Replaces an item in the content list and updates the viewer's inventory if visible.
      Parameters:
      index - the content index to replace
      newItem - the new item
      Returns:
      this menu instance
    • setItems

      public PaginationMenu setItems(List<org.bukkit.inventory.ItemStack> newItems)
      Replaces all items in the menu and refreshes the view if open.
      Parameters:
      newItems - the new item list
      Returns:
      this menu instance
    • open

      public void open(org.bukkit.entity.Player player)
      Opens the menu for the specified player.
      Parameters:
      player - the player to open the menu for
    • destroy

      public void destroy()
      Unregisters all event listeners for this menu.
    • getTotalPages

      public int getTotalPages()
      Returns the total number of pages based on the current items.
      Returns:
      the total page count
    • onInventoryClick

      public void onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event)
      Handles inventory click events, routing to page navigation, action buttons, or content callbacks.
      Parameters:
      event - the inventory click event
    • onInventoryClose

      public void onInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event)
      Cleans up the menu when the inventory is closed, unless a page transition is in progress.
      Parameters:
      event - the inventory close event