Create severale pages menu
Methods
What's several page menu ?
several page menu is chest menu that allow you several pages. All pagination page logic is already set, you just have to place your items.
Create your first menu
public class MySimpleMenu extends ChestPaginationMenu {
public MySimpleMenu(JavaPlugin plugin) {
int menuSize = 27;
super(plugin, "My Menu Title", menuSize);
}
@Override
protected void onCloseMenu(Player player) {
//event when user open your menu
}
@Override
protected void onOpenMenu(Player player) {
//event when user close your menu
}
@Override
protected void onSwitchPage(Player player, int page) {
//event when user chnage page
}
}Now you have your menu, let's add it to menu system.
public MyPlugin extends JavaPlugin {
GuiManager guiManager;
public MyPlugin() {
}
private void initMyMenus() {
MySimpleMenu simpleMenu = new MySimpleMenu(this);
guiManager.registerMenus(simpleMenu, "MySimpleMenu");
}
}To init GuiManager, please refer to this documentation :
Add items in menu
public class MySimpleMenu extends ChestPaginationMenu {
public MySimpleMenu(JavaPlugin plugin) {
...
GuiItem item = new GuiItem(...);
// add item in slot 2 page 0
addItem(item, 2, 0);
}
@Override
protected void onOpenMenu(Player player) {
GuiItem otherItem = new GuiItem(...);
// place only for the player otherItem in slot 3 page 1
addItem(player, otherItem, 3, 1);
}
}This version is outdated. Please download latest release with versioning check system.
Some methods explained before does not exist in this version.
Why use GuiMenuPages ?
GuiMenuPages is made to create easly a menu that contains the number of pages you want.
This class is better than GuiMenu for severale pages.
As the same way as GuiMenu, GuiMenuPages contains constructor, init function and update function.
Let's see how to create this menu !
public class MyMenu extends GuiMenuPages {
public MyMenu(MyPlugin plugin) {
// the 1st argument is your plugin class
// the 2nd argument is the number of slots in your menu
// the 3rd argument is your menu title
// the 4th argument set your menu static or not
super(plugin, 9, "My Menu Title", true);
}
@Override
protected void initGUI() {
super.initGUI();
System.out.println("Init My Menu !");
}
@Override
protected void onOpenMenu(Player player) {
super.onOpenMenu(player);
System.out.println("My menu is open !");
}
@Override
protected void onCloseMenu(Player player) {
super.onCloseMenu(player);
System.out.println("My menu is close !");
}
}Your menu size is your content size. Do not calculate size with next and previous page items. It is added automatically in your menu.
To save your menu in the easy menu plugin please follow the instruction in Create normal menu.
Last updated