0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/spigot.git synced 2024-11-21 20:56:14 +00:00
spigot/CraftBukkit-Patches/0018-Properly-Close-Inventories.patch
2024-10-23 02:15:00 +11:00

45 lines
2.2 KiB
Diff

From 30021cd79e53b6795a7f8942bce2d6a11ec1387f Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
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/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
index e1b103eefb..3019f6b686 100644
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
@@ -1121,6 +1121,15 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
}
public void unload(Chunk chunk) {
+ // Spigot Start
+ for (net.minecraft.world.level.block.entity.TileEntity tileentity : chunk.getBlockEntities().values()) {
+ if (tileentity instanceof net.minecraft.world.IInventory) {
+ for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(((net.minecraft.world.IInventory) tileentity).getViewers())) {
+ h.closeInventory();
+ }
+ }
+ }
+ // Spigot End
chunk.clearAllBlockEntities();
chunk.unregisterTickContainerFromLevel(this);
}
@@ -2101,6 +2110,13 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
public void onTrackingEnd(Entity entity) {
org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot
+ // Spigot Start
+ if (entity.getBukkitEntity() instanceof org.bukkit.inventory.InventoryHolder && (!(entity instanceof EntityPlayer) || entity.getRemovalReason() != Entity.RemovalReason.KILLED)) { // SPIGOT-6876: closeInventory clears death message
+ for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(((org.bukkit.inventory.InventoryHolder) entity.getBukkitEntity()).getInventory().getViewers())) {
+ h.closeInventory();
+ }
+ }
+ // Spigot End
WorldServer.this.getChunkSource().removeEntity(entity);
if (entity instanceof EntityPlayer entityplayer) {
WorldServer.this.players.remove(entityplayer);
--
2.47.0