Skip to content

Container Menus

PineLib provides a simple way to create container menus that can be used for various purposes, such as custom inventories, shops, or any other GUI-based interactions.

There are many different types of container menus available in PineLib, each with its own unique features and use cases:

ClassDescription
ChestMenuA chest inventory with 1-6 rows
CrafterMenuA crafter-type inventory
DropperMenuA dropper-type inventory
ContainerMenuGeneric base class for any Bukkit Inventory
AnvilMenuAn anvil-based text input menu

A MenuItem wraps a ItemStack with an optional click handler.

// From a Material or ItemStack, with a click action
MenuItem.of(Material material, Consumer<InventoryClickEvent> clickAction)
MenuItem.of(ItemStack item, Consumer<InventoryClickEvent> clickAction)
// From a Material or ItemStack, no click action
MenuItem.of(Material material)
MenuItem.of(ItemStack item)
// Direct constructor
new MenuItem(ItemStack item, Consumer<InventoryClickEvent> clickAction)
MethodDescription
getItem()Returns the underlying ItemStack
setItem(ItemStack)Replaces the underlying ItemStack
getClickAction()Returns the click action consumer
setClickAction(Consumer<InventoryClickEvent>)Replaces the click action

The base class for chest, crafter, and dropper menus. Can also be constructed directly with any Bukkit Inventory.

new ContainerMenu(Inventory inventory)

Adds a MenuItem to the first available empty slot.

  • If strict is true, throws IllegalStateException when no empty slot is found.
  • If strict is false, the item is silently dropped if the inventory is full.

Places a MenuItem at the given 0-based slot index, replacing any existing item.

Returns the MenuItem at the given slot, or null if no item is set there.

Fills all empty slots with the given MenuItem.

Fills all slots with the given MenuItem. If override is true, existing items are replaced.

fill(MenuItem menuItem, boolean override, int start)

Section titled “fill(MenuItem menuItem, boolean override, int start)”

Fills slots from start (inclusive) to the end of the inventory.

fill(MenuItem menuItem, boolean override, int start, int end)

Section titled “fill(MenuItem menuItem, boolean override, int start, int end)”

Fills slots from start to end (both inclusive).

Opens the menu for the specified player and registers per-player click/close listeners. The player must be online.

onClose(Consumer<InventoryCloseEvent> closeAction)

Section titled “onClose(Consumer<InventoryCloseEvent> closeAction)”

Registers an action that fires whenever any player closes this inventory.

Unregisters all event listeners. Should be called when the plugin is disabled or the menu is no longer needed.


Extends ContainerMenu. Creates a chest inventory with a configurable number of rows.

new ChestMenu(Component title, int rows)
  • rows must be between 1 and 6 (inclusive), otherwise an IllegalArgumentException is thrown.

Example:

ChestMenu menu = new ChestMenu(Component.text("My Shop"), 3);
menu.set(13, MenuItem.of(Material.DIAMOND, event -> player.sendMessage("Clicked!")));
menu.show(player);

Extends ContainerMenu. Creates a crafter-type inventory.

new CrafterMenu(Component title)

Extends ContainerMenu. Creates a dropper-type inventory.

new DropperMenu(Component title)

An anvil-based menu that captures the text a player types into the rename field and passes the resulting ItemStack to a callback.

new AnvilMenu(Component title, ItemStack startingItem, boolean autoClose, Consumer<ItemStack> clickAction)
ParameterDescription
titleThe title shown at the top of the anvil
startingItemThe item placed in the first anvil slot
autoCloseIf true, the inventory closes automatically when the output slot is clicked
clickActionCalled with the (optionally renamed) result ItemStack when the player clicks the output slot
MethodDescription
show(Player player)Opens the anvil menu for the specified player
getMenuTitle() / setMenuTitle(Component)Get or set the title
getStartingItem() / setStartingItem(ItemStack)Get or set the item in the first slot
getResultItem() / setResultItem(ItemStack)Get or set the item shown in the output slot
setClickAction(Consumer<ItemStack>)Replace the click callback
cleanup()Unregisters all listeners and ProtocolLib adapters

Example:

AnvilMenu menu = new AnvilMenu(
Component.text("Enter a name"),
new ItemStack(Material.PAPER),
true,
result -> player.sendMessage("You typed: " + result.getItemMeta().getDisplayName())
);
menu.show(player);