Skip to content
frosxt edited this page Sep 24, 2023 · 7 revisions

light supports normal menus and paginated Menus. This means that you can make a menu for players to view and interact with that have one page, or support unlimited pages. This is heavily based on NoSequel's menu API, see README for more details.

Paginated Menus

You can create a paginated menu by extending the PaginatedMenu class and calling the super() constructor as well as overriding the setup() method.

Here is an example of a paginated menu:

public class ExamplePaginatedMenu extends PagiantedMenu {
    
    public ExamplePaginatedMenu(Player player) {
        super(player, "&7&lPAGINATED MENU TITLE", 18, 2);
        updateMenu();
    }

    @Override
    public void setup() {
        addFiller(FillingType.EMPTY_SLOTS);
        
        for (int i = 0; i < 27; i++) {
            setButton(i, new Button(new ItemBuilder(Material.DIAMOND_SWORD).build())
                    .setDisplayName("&eSlot: " + i)
                    .setClickAction(event -> event.setCancelled(true)));
        }
    }
}

Menus

You can create a menu by extending the Menu class and calling the super() constructor as well as overriding the setup() method

Here is an example of a menu:

public class ExampleMenu extends Menu {
    
    public Menu(Player player) {
        super(player, "&7&lEXAMPLE MENU", 27);
        
        updateMenu();
    }

    @Override
    public void setup() {
        addFiller(FillingType.BORDER);

        setButton(5, new Button(new ItemBuilder(Material.DIAMOND_SWORD).build())
                    .setDisplayName("&eExample Item")
                    .setClickAction(event -> event.setCancelled(true)));
    }
}

Opening a menu

You can open a menu for a player by creating a new instance of your menu class and calling the updateMenu() method. This can be done as follows:

new TagPaginatedMenu(player).updateMenu();

Registering menu handler

You need to register the menu handler on plugin-startup for menus to function properly. This can be achieved by creating a new MenuHandler instance, like such:

new MenuHandler(JavaPlugin);

Configuring menu pagination

You can configure the navigation buttons used for paginated menus with the following methods:

  • setNextPageButton(Button)
  • setPreviousPageButton(Button)
  • setNextPageButtonSlot(int)
  • setPreviousPageButtonSlot(int)

Adding sticky buttons

Sticky buttons are buttons that appear on every page. These need to be added to a Map before being set in the menu, as follows:

Map<Integer, Button> stickyButtons = new HashMap<>();
stickyButtons.put(slot, button);

To add the sticky buttons to the menu, you can use the following method:

setStickyButtons(stickyButtons);

Other methods

  • setMaxPages(int)
  • setTitle(String)
  • setFillerItem(ItemStack)
  • addFiller(FillingType)

Clone this wiki locally