Skip to content
Cosimo edited this page Jan 6, 2025 · 1 revision

Introduction

Many menu libraries and frameworks exist, though they introduce an excess of assumed features with an already unoptimized and bloated core. This simple menu package integrates with the event-driven Spigot API, lets the developer wrap any existing or new Inventory with the IMenu subclasses, take control of all its incoming InventoryEvents and edit its contents and viewers at any moment. The menus offer a fluent and flexible builder design pattern that doesn't require subclassing for simpler use-cases.

The design principle of this package is the following:

  • menus don't need to store states or properties, only actions,
  • states can be stored in action closures or external variables,
  • any extra features are usually unnecessary and can be done with existing code,
    • e.g. pagination can be done using lambdas, caching through array lists or linked lists, and at any point in the code; it's a matter of use-case

Important

To let the menus work, simply do the following in your plugin's initialization: MenuManager.setInstance(new MenuManager(plugin));

Slot utility

Convert row-column coordinate pair indexing to slot indices by choosing zero-based or one-based indexing of rows and columns:

// For default chest inventories:
int zeroBasedSlotIndex = Slot.Zero.from(2, 3);
int oneBasedSlotIndex = Slot.One.from(3, 4);

// Given an inventory context for calculating with columns:
var menu = new Menu(Bukkit.createInventory(null, InventoryType.DISPENSER, "Example menu"));

int slot = Slot.One.from(1, 3, menu.getInventory());

menu.set(new ItemStack(Material.APPLE), slot);
menu.set(new ItemStack(Material.COOKIE), menu -> IntStream.range(0, menu.getInventory().getSize()).toArray());

Clone this wiki locally