Your First Menu
Your First Menu
We are going to build a 3-row welcome menu with:
- a centered paper button
- a simple border
- a click action that sends a message
Every Lotus menu is just a class that answers three questions:
- What is the title?
- How large is the inventory?
- Which buttons go into which slots?
Step 1 — Create The Menu Class
public final class WelcomeMenu implements PaperMenu {
@Override
public String name() {
return "welcome";
}
@Override
public Component title(MenuView<Component, ?> view) {
return Component.text("Welcome, " + view.viewer().getName());
}
@Override
public Capacity capacity(MenuView<Component, ?> view) {
return Capacity.ofRows(3);
}
@Override
public Content content(MenuView<Component, ?> view) {
return Content.builder(view.capacity())
.fillBorder(Button.of(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)))
.set(1, 4, Button.clickable(
new ItemStack(Material.PAPER),
(menuView, event) ->
menuView.viewer().sendMessage(Component.text("Hello from Lotus!"))
))
.build();
}
}
}</CodeTabItem> <CodeTabItem value="spigot" label="Spigot 1.8.8" language="java">{
public final class WelcomeMenu implements Menu
@Override
public String name() {
return "welcome";
}
@Override
public String title(MenuView<String, ?> view) {
return ChatColor.GOLD + "Welcome, " + view.viewer().getName();
}
@Override
public Capacity capacity(MenuView<String, ?> view) {
return Capacity.ofRows(3);
}
@Override
public Content content(MenuView<String, ?> view) {
return Content.builder(view.capacity())
.fillBorder(Button.of(new ItemStack(Material.STAINED_GLASS_PANE)))
.set(1, 4, Button.clickable(
new ItemStack(Material.PAPER),
(menuView, event) ->
menuView.viewer().sendMessage(ChatColor.YELLOW + "Hello from Lotus!")
))
.build();
}
} `}
view.viewer() is the player opening the menu. That means your title, size, and content can all
change per player if you want them to.
Step 2 — Open It
Once you have a Lotus instance, opening the menu is a one-liner:
lotus.openMenu(player, new WelcomeMenu());
Lotus now creates the inventory, tracks the live view, routes clicks, and keeps the content tied to that player.
Step 3 — Register It By Name If You Need To
If you want to open menus from commands, config files, or string identifiers, register the menu:
lotus.registerMenu(new WelcomeMenu());
lotus.openMenu(player, "welcome");
Lookup is case-insensitive.
name() is optional. If you do not override it, Lotus uses the class name, such as
WelcomeMenu.
What This Example Teaches You
PaperMenuis the easiest entry point on Paper.Menu<String>is the normal entry point on Spigot.Content.builder(view.capacity())is the standard way to lay out a menu.Button.clickable(...)is the quickest way to add behavior.
Lotus already cancels clicks in the top menu inventory before button dispatch. You do not
need event.setCancelled(true) in simple button handlers just to stop players from taking items.
Where To Go Next
- Learn the grid vocabulary in Capacity, Slots & Slot Masks
- Learn richer layouts in Content Builder
- Learn lifecycle hooks in The Menu Handler