-
Notifications
You must be signed in to change notification settings - Fork 0
MenuItem
virtualWinter edited this page Aug 30, 2025
·
2 revisions
The MenuItem class is a builder for creating and customizing ItemStacks for use in your menus. It provides a fluent interface for setting properties like name, lore, enchantments, and click actions.
You can create a MenuItem from a Material or an existing ItemStack.
// From a Material
ItemStack customItem = new MenuItem(Material.DIAMOND_SWORD)
.name("§cLegendary Sword")
.lore("A powerful weapon.", "Forged in dragon's fire.")
.enchant(Enchantment.DAMAGE_ALL, 5)
.glow()
.build();
// From an existing ItemStack
ItemStack enchantedBook = new ItemStack(Material.ENCHANTED_BOOK);
ItemStack customBook = new MenuItem(enchantedBook)
.name("§aBook of Knowledge")
.build();-
.name(String name): Sets the display name of the item. -
.lore(String... lore): Sets the lore of the item. -
.enchant(Enchantment enchantment, int level): Adds an enchantment to the item. -
.glow(): Makes the item glow by applying a hidden enchantment. -
.action(Consumer<InventoryClickEvent> action): Sets the action to be executed when the item is clicked. -
.build(): Builds the finalItemStack.
The MenuItem class also provides static factory methods for common menu items:
-
MenuItem.placeholder(): A gray stained glass pane, useful for filling empty slots. -
MenuItem.previousPage(): A "Previous Page" button. -
MenuItem.nextPage(): A "Next Page" button. -
MenuItem.closeButton(): A "Close" button. -
MenuItem.confirmButton(): A "Confirm" button. -
MenuItem.cancelButton(): A "Cancel" button.
import club.catmc.utils.menu.MenuBuilder;
import club.catmc.utils.menu.MenuItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
public class MenuExamples {
public void openAdvancedMenu(Player player) {
MenuBuilder builder = MenuBuilder.create("Advanced Menu", 36);
for (int i = 1; i <= 20; i++) {
int finalI = i;
builder.addItem(
new MenuItem(Material.EMERALD, finalI)
.name("§aItem #" + finalI)
.lore("§7Click me!")
.build(),
event -> {
Player p = (Player) event.getWhoClicked();
p.sendMessage("You clicked item #" + finalI);
p.closeInventory();
}
);
}
builder.buildAndOpen(player);
}
}© 2025 CatMC Network. This project is licensed under the ISC License.