Intro
Quick start
Create and open your first XaGUI 1.6.1 menu.
1. Initialize XaGUI once
Store the instance on your plugin so every menu can use it.
public final class MyPlugin extends JavaPlugin {
private XaGui xaGui;
@Override
public void onEnable() {
xaGui = new XaGui(this);
}
@Override
public void onDisable() {
if (xaGui != null) xaGui.closeAll();
}
public XaGui getXaGui() {
return xaGui;
}
}Constructing XaGui registers its inventory listener. Do this once, not every time a player opens a GUI.
2. Create a menu
Rows are Minecraft inventory rows, so a 3-row menu has 27 slots (0 through 26).
public void openShop(Player player) {
GuiMenu menu = plugin.getXaGui().createMenu("&8Starter shop", 3);
menu.fillBorder();
menu.addCloseButton();
GuiButton diamond = new GuiButton(Material.DIAMOND)
.setName("&bFree diamond")
.setLore("&7Click to receive one")
.withListener(event -> {
Player clicker = event.getPlayer();
clicker.getInventory().addItem(new ItemStack(Material.DIAMOND));
clicker.sendMessage("You received a diamond.");
});
menu.setSlot(13, diamond);
menu.open(player);
}GuiButton listeners receive a GuiClickEvent. Useful methods include getPlayer(), getClick(), getSlot(), getClickedButton(), and updateClickedButton().
Important rules
- Menu row counts should normally be between 1 and 6.
- Slot indexes start at
0; the last slot ismenu.getSize() - 1. - Slots are locked by default. Only call
unlockButton(...)when players should move that item. setSlot(...)replaces both item and behavior.updateSlot(...)changes the item while retaining the button listener.open(player)opens page index0.
Next, learn buttons and click handling or build the complete single-page example.