Class PaginationMenu
java.lang.Object
me.tayebyassine.homestead.gui.PaginationMenu
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final recordContext passed to content click callbacks. -
Method Summary
Modifier and TypeMethodDescriptionaddActionButton(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.static PaginationMenu.BuilderCreates a newPaginationMenu.Builderfor the given menu key and inventory size.static PaginationMenu.Builderbuilder(String menuKey, Placeholder titlePlaceholder, int size) Creates a newPaginationMenu.Builderwith a placeholder for the menu title.voiddestroy()Unregisters all event listeners for this menu.intReturns the total number of pages based on the current items.voidonInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event) Handles inventory click events, routing to page navigation, action buttons, or content callbacks.voidonInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event) Cleans up the menu when the inventory is closed, unless a page transition is in progress.voidopen(org.bukkit.entity.Player player) Opens the menu for the specified player.replaceSlot(int index, org.bukkit.inventory.ItemStack newItem) Replaces an item in the content list and updates the viewer's inventory if visible.Replaces all items in the menu and refreshes the view if open.
-
Method Details
-
builder
Creates a newPaginationMenu.Builderfor the given menu key and inventory size.- Parameters:
menuKey- the menu title keysize- 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 newPaginationMenu.Builderwith a placeholder for the menu title.- Parameters:
menuKey- the menu title keytitlePlaceholder- the placeholder to apply to the titlesize- 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 displaycallback- the click callback- Returns:
- this menu instance
-
replaceSlot
Replaces an item in the content list and updates the viewer's inventory if visible.- Parameters:
index- the content index to replacenewItem- the new item- Returns:
- this menu instance
-
setItems
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
-