Creating Custom Inventories
Learn how to create custom inventory menus programmatically using the InventoryBuilder class with support for placeholders, mathematical expressions, and automatic command registration.
Table of Contents
Basic Usage
Creating a Simple Inventory
import me.yleoft.zAPI.inventory.InventoryBuilder;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public class Example {
public void openSimpleMenu(Player player) {
// Create an inventory with a title and 3 rows
Component title = TextFormatter.transform("<gold><bold>My Custom Menu");
InventoryBuilder builder = new InventoryBuilder(title, 3);
// Add items (we'll cover this in detail later)
ItemStack item = new ItemStack(Material.DIAMOND);
builder.setItem(0, item);
// Build and open the inventory
Inventory inventory = builder.build();
player.openInventory(inventory);
}
}Creating from YAML Configuration
Constructor Options
1. Manual Constructor
2. Config Constructor (Without Player)
3. Config Constructor (With Player)
4. Config Constructor (With Custom Placeholders)
Available Placeholders
Inventory-Level Placeholders
Placeholder
Description
Example Value
Slot-Level Placeholders
Placeholder
Description
Example Value
PlaceholderAPI Support
Custom Placeholders
Creating Inventories from Config
Automatic Command Registration
Example Config with Command
Inventory Properties
Getting and Setting Title
Getting Inventory Information
Item Management
Adding Items
Removing Items
Checking Items
Advanced Features
Using Global Placeholders
Mathematical Expressions in Placeholders
Copying an Inventory
Building the Final Inventory
Complete Example
Best Practices
See Also
Last updated
Was this helpful?
