Skip to content
FlameyosFlow edited this page Sep 26, 2023 · 8 revisions

Menu Types

Menus have a bunch of inventory types, some lose their functionality when using Bukkit.createInventory (such as workbench so that you use player.openWorkbench(...), and that's okay)

  • CHEST (Default)
  • HOPPER
  • DISPENSER
  • WORKBENCH
  • FURNACE
  • BREWING

Menu Implementation Types

Menu:

it's a regular Inventory with many more features and faster than a normal spigot Inventory.

It's a basic menu for creating interactive menus in Spigot plugins. It allows you to add menu items, handle player interactions, display the menu to players and more.

Generally, all Menus run on only one event, this can prevent boilerplate, improve memory and performance (this is normal menus library behavior, I'm not special haha)

The example usage and initialization of Menu is:

// I know that it's not a good idea to have inconsistent ways of making different menu like new Menu and PaginatedMenu#create
// this inconsistency is only temporary

Menu menu = new Menu(5, "Menu");

// helpers
Filler filler = menu.getFiller(); // fills borders or the entire menu

PaginatedMenu:

it's a class that allows you to create menus with multiple pages.

It automatically handles pagination by dividing your menu items into pages based on the specified page size.

Users can navigate through the pages using navigation buttons.

It provides a convenient way to organize and display a large number of menu items in a user-friendly manner.

It's a more advanced Menu generally, it's been implemented in many popular inventory libraries, frameworks or apis, including:

  • Woody
  • Vision
  • triumph-gui
  • InventoryFramework
  • and much more.

The example usage and initialization of PaginatedMenu is:

PaginatedMenu menu = PaginatedMenu.create("Menu", 5, 3); // 5 = rows, 3 = page count (how many pages this menu will contain by default)

// or with pre-set modifiers
PaginatedMenu menu = PaginatedMenu.create("Menu", 5, 3, EnumSet.of(Modifier.PREVENT_ITEM_REMOVAL, ...));

// menu helpers
PageDecoration decoration = menu.getPageDecorator(); // decorate borders and the entire menu too
Pages pages = menu.getPages(); // get pages, add/set/remove items in every page (might be performance costly if not done right), etc

PaginatedMenu#getFiller will work but only for the current page.

PaginatedMenu#getPages CAUTION

using Pages#setPageItems, Pages#addPageItems and Pages#removePageItems can be performance-expensive and be used properly. often, the better solution is to have your own pages loop and do stuff and that way you can have the best performance.

use them when all you need can just be a few methods or you can't use a for loop for some reason.

Opening the Menu

Use this to open the menu for a Player:

menu.open(player);

// if you're using SeparatedPagedMenu
menu.open();

More coming out (inshallah)