Skip to content

Creating an inventory

Dalton edited this page Nov 19, 2021 · 11 revisions

How do you create an inventory?

Creating on is rather simple, you take a PluginInventory instance and initialize it like so:

PluginInventory inventory = new PluginInventory(9, "&a&lInventory");

You may notice there is 2 arguments, the 1st argument is for the inventory slot count, which goes by increments of 9 up to a maximum of 54. The second argument is what the inventory will be named.

Further editing

This section will explain further editing you can do to the PluginInventory object!

Changing the Slot and Inventory name after creating the PluginInventory instance.

This is rather simple, it may be achieved like so:

PluginInventory inventory = new PluginInventory(9, "&a&lInventory")
    .setInventorySize(18)
    .setDisplayName("&b&lNew Name");

Adding an InventoryHolder

To add a InventoryHolder, you first need to have a InventoryHolder created, you can view more here and here

Once you have your holder, simple add it to the PluginInventory instance:

PluginInventory inventory = new PluginInventory(9, "&a&lInventory")
    .setInventoryHolder(yourHolder);

PluginInventory Events

This library comes with a very extensive EventApi for inventories!

WARNING!! If you using anything with events with this library PLEASE look into this method to register the PluginInventory to the Event Bust!!!

Adding an onClose event

Adding an onClose event can be added like so:

PluginInventory inventory = new PluginInventory(9, "&a&lInventory")
    .onClose((closeEvent) -> {
        // Close event matches InventoryCloseEvent: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/inventory/InventoryCloseEvent.html
    });

Adding an onOpen event

Adding an onOpen event can be added like so:

PluginInventory inventory = new PluginInventory(9, "&a&lInventory");
    .onOpen((openEvent) -> {
        // Open event matches InventoryOpenEvent: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/inventory/InventoryOpenEvent.html
    });

Adding an onClick event

Please note, if you are wanting to handle click event per item, please see ClickableItem

To add a onClick event can be added like so:

PluginInventory inventory = new PluginInventory(9, "&a&lInventory")
    .onClick((onClick) -> {
        // Click event matches InventoryCLickEvent: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/inventory/InventoryClickEvent.html
    });
Clone this wiki locally