[SPIGOT-2486] Chest inventory not updating when edited via Plugin when the chunk has been reloaded Created: 04/Jul/16 Updated: 05/Jul/16 Resolved: 05/Jul/16 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Major |
Reporter: | Sabbertran | Assignee: | Unassigned |
Resolution: | Won't Fix | Votes: | 0 |
Labels: | chest, chunk, inventory, update | ||
Environment: |
Spigot server with no other plugin which could be interfering with the chest edit |
Description |
When trying to lower the stack size of an ItemStack in a chest after the chunk has been reloaded (leave and reenter the area) after the first, initial chunk load, the chest inventory is not updating. chest.getChunk().load(true); for (int i = 0; i < chest.getInventory().getSize(); i++) { ItemStack is = chest.getInventory().getItem(i); if (is != null) { getServer().getLogger().info("stack has " + is.getAmount() + " items"); is.setAmount(is.getAmount() - amount); chest.getInventory().setItem(i, is); chest.update(true); } } The behaviour is also described in the post on the forums: https://www.spigotmc.org/threads/chest-inventory-update-not-working.159674/ |
Comments |
Comment by md_5 [ 05/Jul/16 ] |
Yes. You can't keep references to most Bukkit objects, they grow stale. |
Comment by Sabbertran [ 04/Jul/16 ] |
Already tried cloning the stack and using it without update. Doesn't work either. |
Comment by Black Hole [ 04/Jul/16 ] |
A a workaround you could set a clone of the item stack. Also please try without using chest.update(true); |