Create simple menu
Here we gonna talk about how create a menu
Methods
Code example
What's simple menu ?
simple menu is only 1 chest page menu. It does not allow you to create several page.
Create your first menu
public class MySimpleMenu extends ChestMenu {
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
}
}
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 ChestMenu {
public MySimpleMenu(JavaPlugin plugin) {
...
GuiItem item = new GuiItem(...);
// add item in slot 2
addItem(item, 2);
}
@Override
protected void onOpenMenu(Player player) {
GuiItem otherItem = new GuiItem(...);
// place only for the player otherItem in slot 3
addItem(player, otherItem, 3);
}
}
Refresh user page
public class MySimpleMenu extends ChestMenu {
public MySimpleMenu(JavaPlugin plugin) {
...
}
@Override
protected void onOpenMenu(Player player) {
GuiItem otherItem = new GuiItem(...)
.setDisableEvent(true)
.setAction(ItemActions.LEFT_CLICK, new ItemGuiAction() {
@Override
public void run(Player player, JavaPlugin plugin) {
refreshPage(player);
}
});
// when player gonna click on item, its menu will refresh
addItem(player, otherItem, 3);
}
}
Last updated