XaGui Docs
Examples

Data-driven paginated menu

Calculate pages and distribute entries across them.

This pattern is adapted from a working plugin using XaGUI 1.6.1. A six-row bordered menu has 28 convenient content slots.

public GuiMenuInterface buildCatalog(List<Material> entries) {
    int[] contentSlots = {
        10, 11, 12, 13, 14, 15, 16,
        19, 20, 21, 22, 23, 24, 25,
        28, 29, 30, 31, 32, 33, 34,
        37, 38, 39, 40, 41, 42, 43
    };

    int pages = Math.max(1,
            (int) Math.ceil(entries.size() / (double) contentSlots.length));

    GuiMenu menu = xaGui.createMenu("&8Material catalog", 6, pages);
    menu.fillBorder();
    menu.addCloseButtonAllPages();
    menu.addPaginator();
    menu.setPageSwitchSound(Sound.ITEM_BOOK_PAGE_TURN);

    for (int index = 0; index < entries.size(); index++) {
        int page = index / contentSlots.length;
        int slot = contentSlots[index % contentSlots.length];
        Material material = entries.get(index);

        menu.setSlot(page, slot, new GuiButton(material)
                .setName("&e" + material.name())
                .withListener(event ->
                        event.getPlayer().sendMessage("Selected " + material.name())));
    }

    return menu;
}

Open it with buildCatalog(materials).open(player). Build content before opening because open(player) starts at page index 0.