-
Notifications
You must be signed in to change notification settings - Fork 3
Menus
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.
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)));
}
}
}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)));
}
}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();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);You can configure the navigation buttons used for paginated menus with the following methods:
setNextPageButton(Button)setPreviousPageButton(Button)setNextPageButtonSlot(int)setPreviousPageButtonSlot(int)
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);setMaxPages(int)setTitle(String)setFillerItem(ItemStack)addFiller(FillingType)