mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-05 10:20:53 +01:00
bdcc31caad
I had did a few of the operations myself, which would have broken chunkCheck from doing it itself, which would leave some state left in the original chunk and thats not good....
83 lines
3.6 KiB
Diff
83 lines
3.6 KiB
Diff
From 175f1aa581f5c3bd0f35201fcf5a5429da491b8a 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 16f2e32d2..9cb4e5a1e 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 779da0650..a4f34293f 100644
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
|
@@ -520,6 +520,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
|
|
@@ -1344,6 +1345,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 )
|
|
{
|
|
@@ -1405,9 +1419,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();
|
|
--
|
|
2.25.1
|
|
|