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

setEditable bug #151

Open gobboo opened 4 years ago

gobboo commented 4 years ago

I understand it's not on a release build but when using setEditable on my inventory doesn't update, here is my code:

public static void onInventoryClick(InventoryClickEvent e) {
        Player player = (Player) e.getWhoClicked();

        SkyEnchants.getInvManager().getInventory(player).ifPresent(inventory -> {
            if(!inventory.getId().equalsIgnoreCase("enchantmentTable")) return;

            ItemStack newItem = e.getCursor();

            SkyEnchants.getInvManager().getContents(player).ifPresent(contents -> {
                if(canEnchant(newItem)) {
                    System.out.println(newItem); // THIS RUNS 

                    int bookshelvesInRange = getNearbyBooks(player.getLocation(), 5);

                    ItemStack lowEnchant = new ItemStack(Material.EXP_BOTTLE);
                    ItemMeta lowMeta = lowEnchant.getItemMeta();
                    lowEnchant.setAmount(calculateEnchantLevel(15, bookshelvesInRange, 0.9));
                    lowMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&aEnchant Item &8- &6Level " + lowEnchant.getAmount()));
                    lowEnchant.setItemMeta(lowMeta);
                    contents.set(3, 2, ClickableItem.from(lowEnchant, event -> enchantItem(newItem, contents)));

Now the print Runs, however the content does not get updated at all? The slot I put items in:

https://i.imgur.com/PpXwfsS.png

Is editable and is of Clickable NONE.

Now if I click this sword onto anythign else everything updates fine, now I'm sure if my code is bad but I've tested so many things and I've come to the conclusion that it's either setEditable misfunctioning or this is intended.

MinusKube commented 4 years ago

Did you try cancelling the event?

gobboo commented 4 years ago

Did you try cancelling the event?

Surely if I cancel the event then I can't place the item in at all?

Here is an aexample of what is happening and how it only updates after I click on something https://gfycat.com/SlushyHonestBlueandgoldmackaw

But I assume its a drag event then but I've tried that and that doesn't get called at ALL or when it does its like 1/20