Paper/Spigot-Server-Patches/0448-Ensure-Entity-is-never-double-registered.patch
Aikar 827cc63263
Updated Upstream (Bukkit/CraftBukkit/Spigot)
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:
ffc8e4ca SPIGOT-5716: Clarify documentation of MultipleFacing

CraftBukkit Changes:
d07a78b1 SPIGOT-5716: Clarify documentation of MultipleFacing
46a13860 SPIGOT-5718: Block.BreakBlockNaturally does not reflect tool used
214ffea9 SPIGOT-5727: GameRule doImmediateRespawn cannot be set per-world

Spigot Changes:
2f5d615f SPIGOT-5730: Modernise inventory patch
a2bdb119 SPIGOT-5679: Add config option for end portal activation sound

Closes #3352
2020-05-12 01:27:07 -04:00

80 Zeilen
3.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 29 Mar 2020 18:26:14 -0400
Subject: [PATCH] Ensure Entity is never double registered
If something calls register twice, and the world is ticking, it could be
enqueued to add twice.
Vs behavior of non ticking of just overwriting state.
We will now simply log a warning when this happens instead of crashing the server.
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 7bdd3f19b2bc51c4f995d42fcd47e0e315310bff..7434f859f7f9acff0f881ff594c8dffdfa249c76 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -59,6 +59,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
// Paper start
+ boolean isQueuedForRegister = false;
public static Random SHARED_RANDOM = new Random() {
private boolean locked = false;
@Override
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index be61f898cc96afeffe6ff2eb0ae3c4ce8da10b80..e635839673b767c630d0d3a2a7c370b05bba7164 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -532,6 +532,7 @@ public class WorldServer extends World {
try (co.aikar.timings.Timing ignored = this.timings.newEntities.startTiming()) { // Paper - timings
while ((entity = (Entity) this.entitiesToAdd.poll()) != null) {
+ if (!entity.isQueuedForRegister) continue; // Paper - ignore cancelled registers
this.registerEntity(entity);
}
} // Paper - timings
@@ -1338,6 +1339,19 @@ public class WorldServer extends World {
public void unregisterEntity(Entity entity) {
org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot
+ // Paper start - fix entity registration issues
+ if (entity instanceof EntityComplexPart) {
+ // Usually this is a no-op for complex parts, and ID's should be removed, but go ahead and remove it anyways
+ // Dragon parts are handled special in register. they don't receive a valid = true or register by UUID etc.
+ this.entitiesById.remove(entity.getId(), entity);
+ return;
+ }
+ if (!entity.valid) {
+ // Someone called remove before we ever got added, cancel the add.
+ entity.isQueuedForRegister = false;
+ return;
+ }
+ // Paper end
// Spigot start
if ( entity instanceof EntityHuman )
{
@@ -1404,9 +1418,21 @@ public class WorldServer extends World {
private void registerEntity(Entity entity) {
org.spigotmc.AsyncCatcher.catchOp("entity register"); // Spigot
+ // Paper start - don't double enqueue entity registration
+ //noinspection ObjectEquality
+ if (this.entitiesById.get(entity.getId()) == entity) {
+ LOGGER.error(entity + " was already registered!");
+ new Throwable().printStackTrace();
+ return;
+ }
+ // Paper end
if (this.tickingEntities) {
- this.entitiesToAdd.add(entity);
+ if (!entity.isQueuedForRegister) { // Paper
+ this.entitiesToAdd.add(entity);
+ entity.isQueuedForRegister = true; // Paper
+ }
} else {
+ entity.isQueuedForRegister = false; // Paper
this.entitiesById.put(entity.getId(), entity);
if (entity instanceof EntityEnderDragon) {
EntityComplexPart[] aentitycomplexpart = ((EntityEnderDragon) entity).eo();