[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.
As said, this only happens after the chunk has been unloaded. After first entering the chunk everything is working fine.

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.
It seems as if the chest gui is not registering the update correctly, because if I rerun the code, the logged stack size is also decreased, how it should be.

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);

Generated at Tue Apr 15 11:10:56 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.