Paper/Spigot-Server-Patches/0452-Prevent-Double-PlayerChunkMap-adds-crashing-server.patch
Aikar 36f34f01c0
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
da9ef3c5 #496: Add methods to get/set ItemStacks in EquipmentSlots
3abebc9f #492: Let Tameable extend Animals rather than Entity
941111a0 #495: Expose ItemStack and hand used in PlayerShearEntityEvent
4fe19cae #494: InventoryView - Add missing Brewing FUEL_TIME

CraftBukkit Changes:
933e9094 #664: Add methods to get/set ItemStacks in EquipmentSlots
18722312 #662: Expose ItemStack and hand used in PlayerShearEntityEvent
2020-05-06 06:05:22 -04:00

49 lines
2.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 2 Apr 2020 01:42:39 -0400
Subject: [PATCH] Prevent Double PlayerChunkMap adds crashing server
Suspected case would be around the technique used in .stopRiding
Stack will identify any causer of this and warn instead of crashing.
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index 6eb055913177b0c01a027b2b356190dc561072c5..4beae504c875767ff00e26461fe7240498750e27 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -1446,6 +1446,14 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
protected void addEntity(Entity entity) {
org.spigotmc.AsyncCatcher.catchOp("entity track"); // Spigot
+ // Paper start - ignore and warn about illegal addEntity calls instead of crashing server
+ if (!entity.valid || entity.world != this.world || this.trackedEntities.containsKey(entity.getId())) {
+ new Throwable("[ERROR] Illegal PlayerChunkMap::addEntity for world " + this.world.getWorld().getName()
+ + ": " + entity + (this.trackedEntities.containsKey(entity.getId()) ? " ALREADY CONTAINED (This would have crashed your server)" : ""))
+ .printStackTrace();
+ return;
+ }
+ // Paper end
if (!(entity instanceof EntityComplexPart)) {
if (!(entity instanceof EntityLightning)) {
EntityTypes<?> entitytypes = entity.getEntityType();
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 9fbe8fa1b2bb98b45fb406fcaf146d0e0b34c0ef..2a7a47c6707c349af55ccd70eb3b8c48387c391a 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -1472,7 +1472,7 @@ public class WorldServer extends World {
}
}
- this.getChunkProvider().addEntity(entity);
+ // this.getChunkProvider().addEntity(entity); // Paper - moved down below valid=true
// CraftBukkit start - SPIGOT-5278
if (entity instanceof EntityDrowned) {
this.navigators.add(((EntityDrowned) entity).navigationWater);
@@ -1483,6 +1483,7 @@ public class WorldServer extends World {
this.navigators.add(((EntityInsentient) entity).getNavigation());
}
entity.valid = true; // CraftBukkit
+ this.getChunkProvider().addEntity(entity); // Paper - from above to be below valid=true
// Paper start - Set origin location when the entity is being added to the world
if (entity.origin == null) {
entity.origin = entity.getBukkitEntity().getLocation();