From 846fc496d915908dcc67a043e0261ade0b4f82ff Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 27 Jun 2013 17:26:09 +1000 Subject: [PATCH] Properly Close Inventories Properly close inventories when unloading and switching worlds. diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java index 20b945c..f68abb4 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -761,6 +761,18 @@ public class Chunk { while (iterator.hasNext()) { TileEntity tileentity = (TileEntity) iterator.next(); + // Spigot Start + if ( tileentity instanceof IInventory ) + { + for ( org.bukkit.entity.HumanEntity h : Lists.newArrayList((List) ( (IInventory) tileentity ).getViewers() ) ) + { + if ( h instanceof org.bukkit.craftbukkit.entity.CraftHumanEntity ) + { + ( (org.bukkit.craftbukkit.entity.CraftHumanEntity) h).getHandle().closeInventory(); + } + } + } + // Spigot End this.world.b(tileentity); } @@ -771,6 +783,18 @@ public class Chunk { java.util.Iterator iter = newList.iterator(); while (iter.hasNext()) { Entity entity = iter.next(); + // Spigot Start + if ( entity instanceof IInventory ) + { + for ( org.bukkit.entity.HumanEntity h : Lists.newArrayList( (List) ( (IInventory) entity ).getViewers() ) ) + { + if ( h instanceof org.bukkit.craftbukkit.entity.CraftHumanEntity ) + { + ( (org.bukkit.craftbukkit.entity.CraftHumanEntity) h).getHandle().closeInventory(); + } + } + } + // Spigot End // Do not pass along players, as doing so can get them stuck outside of time. // (which for example disables inventory icon updates and prevents block breaking) -- 2.5.0