MinusKube / SmartInvs

Advanced Inventory API for your Minecraft Bukkit plugins.
https://minuskube.gitbook.io/smartinvs/
Apache License 2.0
263 stars 65 forks source link

Clickable Item: Event does not fire #162

Closed alvileg closed 3 years ago

alvileg commented 4 years ago

Hello, I was testing this plugin, and when clicking an item, the event does not fire. I am using Spigot 1.16.3

Here is the code:

` public class TaskPickerGUI implements InventoryProvider {

public static final SmartInventory INVENTORY = SmartInventory.builder()
        .id("taskManger")
        .manager(BetweenUs.getInstance().inv)
        .provider(new TaskPickerGUI())
        .size(5,9)
        .title("Task Manager")
        .build();

@Override
public void init(Player player, InventoryContents inventoryContents) {
    inventoryContents.fillRow(4, ClickableItem.empty(new ItemStack(Material.GRAY_STAINED_GLASS_PANE)));
    inventoryContents.set(4, 0, ClickableItem.of(new ItemBuilder(Material.BARRIER, 1, (short) 0)
                    .setName(ChatColor.RED + "Close Menu")
                    .build(),
            e -> {
                TaskPickerGUI.INVENTORY.close(player);
                System.out.println("THIS IS BEING EXECUTED: POG");
            }

    ));

    inventoryContents.set(4,4, ClickableItem.of(new ItemBuilder(Material.CRAFTING_TABLE,1, (short) 0)
                    .setName(ChatColor.YELLOW + "Tasks Library")
                    .build(),
            e -> {
        TaskLibraryGUI.INVENTORY.open(player);
                System.out.println("THIS IS BEING EXECUTED: LOL");
    })

    );
    inventoryContents.set(1, 1, ClickableItem.of(new ItemStack(Material.POTATO),
            e -> player.sendMessage(ChatColor.GOLD + "You clicked on a potato.")));

}

@Override
public void update(Player player, InventoryContents inventoryContents) {

}

}

` No errors in console. GUI opens, but when clicking an item, nothing happens

flynow10 commented 4 years ago

I have the same problem.

Jydett commented 4 years ago

Hi, what version of SmartInvs are you both using ?

A little test on my side with SmartInvs in 1.3.0 (& spigot 1.6.3) this works perfectly fine both with the old API :

            .type(type)
            .provider(new InventoryProvider() {
                @Override
                public void init(Player player, InventoryContents contents) {
                    contents.set(1, 1, ClickableItem.of(new ItemStack(Material.POTATO),
                            e -> player.sendMessage(ChatColor.GOLD + "You clicked on a potato.")));
                }

                @Override
                public void update(Player player, InventoryContents contents) {}
            })
            .closeable(true)
            .build().open(player);

And with the new API :

SmartInventory.builder()
            .type(type)
            .provider(new InventoryProvider() {
                @Override
                public void init(Player player, InventoryContents contents) {
                    contents.set(1, 1, ClickableItem.of(new ItemStack(Material.POTATO),
                            e -> player.sendMessage(ChatColor.GOLD + "You clicked on a potato.")));
                }

                @Override
                public void update(Player player, InventoryContents contents) {}
            })
            .closeable(true)
            .build().open(player);

Make sure that you register yourself correctly if you are using this lib as a dependancy (and not as a plugin) : SmartInvsPlugin.setPlugin(this);

As you use your own InventoryManager, make sure to initialize it with the init() method.