Skip to content

Creating a ClickableItems

Dalton edited this page Apr 24, 2022 · 4 revisions

Creating a ClickableItem is rather simple:

ClickableItem item = new ClickableItem(Material.STONE, 1);

Handling the ClickableItem's InventoryClickEvent

To handle the ClickableItem's InventoryClickEvent, you simply call the onClick functional interface:

ClickableItem item = new ClickableItem(Material.STONE, 1)
    .onClick((onClick) -> {
        final InventoryClickEvent event = onClick.clickEvent();
        // Do things with event for this specific item
    });

Adding ClickableItem to an inventory

Make sure you read Creating a PluginInventory first before reading the rest of this guide

There is a few different methods:

  • Setting a specific slots ClickableItem
ClickableItem item = new ClickableItem(Material.STONE, 1)
    .onClick((onClick) -> {
        final InventoryClickEvent event = onClick.clickEvent();
        // Do things with event for this specific item
    });
            
PluginInventory inventory = new PluginInventory(9, "&a&lInventory")
    .setClickableItemAtSlot(0, item);
  • Filling all slots with a specific ClickableItem
ClickableItem item = new ClickableItem(Material.STONE, 1)
    .onClick((onClick) -> {
        final InventoryClickEvent event = onClick.clickEvent();
        // Do things with event for this specific item
    });

PluginInventory inventory = new PluginInventory(9, "&a&lInventory")
    .fillWith(0, false);

You are probably about the boolean in this method, its called the overwrite:

When this boolean is true, it will forcefully overwrite all other ClickableItem's previously added to the PluginInventory

When its false, the only slots that get filled are slots that do not currently contain a ClickableItem