2021-08-26 02:16:27 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 11 Mar 2021 03:03:32 -0800
Subject: [PATCH] Do not run close logic for inventories on chunk unload
Still call the event and change the active container though. We
want to avoid close logic because it's possible to load the
chunk through it. This should also be OK from a leak prevention/
state desync POV because the TE is getting unloaded anyways.
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
2022-06-08 10:20:57 +00:00
index 87d7a28aa9060b0576b443cb67cea9e77de8e2f6..ea58a43df4b6637a1a9e736aeead6d88396f6395 100644
2021-08-26 02:16:27 +00:00
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
2022-06-08 10:20:57 +00:00
@@ -1330,9 +1330,13 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-08-26 02:16:27 +00:00
// Spigot Start
for (net.minecraft.world.level.block.entity.BlockEntity tileentity : chunk.getBlockEntities().values()) {
if (tileentity instanceof net.minecraft.world.Container) {
+ // Paper start - this area looks like it can load chunks, change the behavior
+ // chests for example can apply physics to the world
+ // so instead we just change the active container and call the event
for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(((net.minecraft.world.Container) tileentity).getViewers())) {
- h.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNLOADED); // Paper
+ ((org.bukkit.craftbukkit.entity.CraftHumanEntity)h).getHandle().closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNLOADED); // Paper
}
2021-09-11 10:22:51 +00:00
+ // Paper end
2021-08-26 02:16:27 +00:00
}
}
// Spigot End
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2022-06-08 10:20:57 +00:00
index a39a387a744ec1f63c06fc05b431983a6e8bf70a..866e4aa0080363976861fcbfe6aedc380bbc5e53 100644
2021-08-26 02:16:27 +00:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2022-06-08 10:20:57 +00:00
@@ -1589,6 +1589,18 @@ public class ServerPlayer extends Player {
2021-08-26 02:16:27 +00:00
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
this.doCloseContainer();
}
+ // Paper start - special close for unloaded inventory
+ @Override
+ public void closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
+ // copied from above
+ CraftEventFactory.handleInventoryCloseEvent(this, reason); // CraftBukkit
+ // Paper end
+ // copied from below
+ this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
+ this.containerMenu = this.inventoryMenu;
+ // do not run close logic
+ }
+ // Paper end - special close for unloaded inventory
public void doCloseContainer() {
2021-11-25 03:06:43 +00:00
this.containerMenu.removed(this);
2021-08-26 02:16:27 +00:00
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
2022-06-08 10:20:57 +00:00
index c8b87d5f7af7f19968007cbc18359f0af33040a5..520150814d5ceaba80c34b0f4ea0bb7abe4e8269 100644
2021-08-26 02:16:27 +00:00
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
2022-06-08 10:20:57 +00:00
@@ -507,6 +507,11 @@ public abstract class Player extends LivingEntity {
2021-08-26 02:16:27 +00:00
this.containerMenu = this.inventoryMenu;
}
// Paper end
+ // Paper start - special close for unloaded inventory
+ public void closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
+ this.containerMenu = this.inventoryMenu;
+ }
+ // Paper end - special close for unloaded inventory
public void closeContainer() {
this.containerMenu = this.inventoryMenu;