Package dev.oumaimaa.kawaiiapi.menu
Class PaginatedMenu
java.lang.Object
dev.oumaimaa.kawaiiapi.menu.Menu
dev.oumaimaa.kawaiiapi.menu.PaginatedMenu
- All Implemented Interfaces:
org.bukkit.inventory.InventoryHolder
Abstract base class for creating paginated menus with automatic navigation.
Provides built-in support for first/previous/next/last page buttons and
automatic item distribution across multiple pages.
Features:
- Automatic page navigation buttons
- Customizable border items
- Smart caching for performance
- Page information display
- 28 items per page by default
The layout reserves slots 0-9, 17-18, 26-27, 35-36, and 44-53 for borders and navigation, leaving 28 slots for content per page.
- Version:
- 1.0
- Author:
- KawaiiDevelopment
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intFields inherited from class dev.oumaimaa.kawaiiapi.menu.Menu
FILLER_GLASS, inventory, player, playerMenuUtility -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPaginatedMenu(@NotNull PlayerMenuUtility playerMenuUtility) Constructs a new PaginatedMenu instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidSets up the border and navigation buttons for the paginated menu.abstract @NotNull List<org.bukkit.inventory.ItemStack> Converts data objects to ItemStacks for display in the menu.booleanNavigates to the first page.intGets the current page number (1-indexed for display).Provides custom items to override the default menu border buttons.protected @NotNull List<org.bukkit.inventory.ItemStack> getItems()Gets the cached items, or generates them if not cached.intGets the maximum number of items that can be displayed per page.protected intGets the slot offset for the current page.intGets the total number of pages.protected booleanChecks if the menu has a next page available.protected booleanChecks if the menu has a previous page available.protected voidClears the item cache, forcing a refresh on the next access.protected booleanChecks if the current page is empty.booleanlastPage()Navigates to the last page.booleannextPage()Navigates to the next page.voidopen()Opens this menu for the player.booleanprevPage()Navigates to the previous page.voidRefreshes the menu data and reloads items without closing the menu.protected voidsetMaxItemsPerPage(int maxItems) Sets the maximum items per page.voidSets up all items in the menu inventory.Methods inherited from class dev.oumaimaa.kawaiiapi.menu.Menu
back, cancelAllClicks, getInventory, getMenuName, getPlayer, getPlayerMenuUtility, getSlots, handleMenu, handleMenuClose, isOpen, makeItem, makeItem, playSound, reload, reloadItems, sendMessage, setFillerGlass, setFillerGlass
-
Field Details
-
data
-
page
protected int page -
maxItemsPerPage
protected int maxItemsPerPage
-
-
Constructor Details
-
Method Details
-
dataToItems
Converts data objects to ItemStacks for display in the menu. This method is called to populate the menu pages. Results are cached for performance.- Returns:
- List of ItemStacks to be displayed across pages
-
getCustomMenuBorderItems
-
addMenuBorder
protected void addMenuBorder()Sets up the border and navigation buttons for the paginated menu. Can be overridden to create a completely custom border layout. -
getItems
Gets the cached items, or generates them if not cached.- Returns:
- List of ItemStacks for the current menu state
-
invalidateCache
protected void invalidateCache()Clears the item cache, forcing a refresh on the next access. Call this when the underlying data changes. -
setMenuItems
public void setMenuItems()Description copied from class:MenuSets up all items in the menu inventory. Called when the menu is opened or reloaded. Override this method to populate your menu with items.- Specified by:
setMenuItemsin classMenu
-
prevPage
public boolean prevPage()Navigates to the previous page.- Returns:
- true if navigation was successful, false if already on first page
-
nextPage
public boolean nextPage()Navigates to the next page.- Returns:
- true if navigation was successful, false if already on last page
-
firstPage
public boolean firstPage()Navigates to the first page.- Returns:
- true if navigation was successful, false if already on first page
-
lastPage
public boolean lastPage()Navigates to the last page.- Returns:
- true if navigation was successful, false if already on last page
-
getMaxItemsPerPage
public int getMaxItemsPerPage()Gets the maximum number of items that can be displayed per page.- Returns:
- The max items per page (default: 28)
-
setMaxItemsPerPage
protected void setMaxItemsPerPage(int maxItems) Sets the maximum items per page. Call this before opening the menu to adjust pagination.- Parameters:
maxItems- The maximum items per page (must be positive)- Throws:
IllegalArgumentException- if maxItems is not positive
-
getCurrentPage
public int getCurrentPage()Gets the current page number (1-indexed for display).- Returns:
- The current page number
-
getTotalPages
public int getTotalPages()Gets the total number of pages.- Returns:
- The total page count
-
open
-
refreshData
public void refreshData()Refreshes the menu data and reloads items without closing the menu. Call this when the underlying data has changed. -
hasPreviousPage
protected boolean hasPreviousPage()Checks if the menu has a previous page available.- Returns:
- true if there is a previous page
-
hasNextPage
protected boolean hasNextPage()Checks if the menu has a next page available.- Returns:
- true if there is a next page
-
getPageOffset
protected int getPageOffset()Gets the slot offset for the current page. Useful for custom pagination implementations.- Returns:
- The starting index for the current page
-
isCurrentPageEmpty
protected boolean isCurrentPageEmpty()Checks if the current page is empty.- Returns:
- true if there are no items on the current page
-