MinusKube / SmartInvs

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

Updating Contents in Event? #150

Closed gobboo closed 4 years ago

gobboo commented 4 years ago

How would I go about updating the contents of an Inventory on an InventoryClickEvent

At the moment I'm doing this

public static void onInventoryClick(InventoryClickEvent e) {
        if(!e.getInventory().getName().equalsIgnoreCase("§9Enchant Item")) return;
        if(e.getCurrentItem().getType().equals(Material.STAINED_GLASS_PANE) || !e.getCurrentItem().getType().equals(Material.AIR)) return;

        ItemStack newItem = e.getCursor();

        if(isEnchantable(newItem)) {
            Player p = (Player) e.getWhoClicked();

            InventoryContents inv = SkyEnchants.getInvManager().getContents(p).get();

            System.out.println("Can enchant");

            inv.set(3, 2, ClickableItem.from(new ItemStack(Material.EXP_BOTTLE), event -> event.getPlayer().sendMessage("Click")));
            inv.set(3, 4, ClickableItem.from(new ItemStack(Material.EXP_BOTTLE), event -> event.getPlayer().sendMessage("Click")));
            inv.set(3, 6, ClickableItem.from(new ItemStack(Material.EXP_BOTTLE), event -> event.getPlayer().sendMessage("Click")));
        } else {
            System.out.println("Cant enchant");
        }
    }

Which is buggy, as it only updates the inventory if I spam click the item in? but my knowledge of .getContent() is limited and rn I thought it just returned the current open Inventories contents but I might be wrong.

And of course my listener is just .listener(new InventoryListener<>(InventoryClickEvent.class, InventoryInteract::onInventoryClick))

Just wondering what the best method is to update the contents of items in the inventory on an event.

gobboo commented 4 years ago

Updated the code a bit, but I foudn out that if I put the item in the slot then click a glass pane for example which is around the outside it updates ? Idk if this is a bug or not or becasue of the Editable ClickableItem