spigot/CraftBukkit-Patches/0021-Properly-Close-Inventories.patch

55 lines
2.4 KiB
Diff

From 8ede94f0c6f780756fa05ce07e7b77709c142982 Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
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/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index d119a5b19..24d8b2a6a 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -971,6 +971,21 @@ public class WorldServer extends World {
}
public void unloadChunk(Chunk chunk) {
+ // Spigot Start
+ for (TileEntity tileentity : chunk.getTileEntities().values())
+ {
+ if ( tileentity instanceof IInventory )
+ {
+ for ( org.bukkit.entity.HumanEntity h : Lists.<org.bukkit.entity.HumanEntity>newArrayList((List<org.bukkit.entity.HumanEntity>) ( (IInventory) tileentity ).getViewers() ) )
+ {
+ if ( h instanceof org.bukkit.craftbukkit.entity.CraftHumanEntity )
+ {
+ ( (org.bukkit.craftbukkit.entity.CraftHumanEntity) h).getHandle().closeInventory();
+ }
+ }
+ }
+ }
+ // Spigot End
this.tileEntityListUnload.addAll(chunk.getTileEntities().values());
EntitySlice[] aentityslice = chunk.getEntitySlices();
int i = aentityslice.length;
@@ -981,6 +996,18 @@ public class WorldServer extends World {
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
+ // Spigot Start
+ if ( entity instanceof IInventory )
+ {
+ for ( org.bukkit.entity.HumanEntity h : Lists.<org.bukkit.entity.HumanEntity>newArrayList( (List<org.bukkit.entity.HumanEntity>) ( (IInventory) entity ).getViewers() ) )
+ {
+ if ( h instanceof org.bukkit.craftbukkit.entity.CraftHumanEntity )
+ {
+ ( (org.bukkit.craftbukkit.entity.CraftHumanEntity) h).getHandle().closeInventory();
+ }
+ }
+ }
+ // Spigot End
if (!(entity instanceof EntityPlayer)) {
if (this.tickingEntities) {
--
2.20.1