f4e3b4e439
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: 5b680f0b Note maximum objective score length in documentation CraftBukkit Changes: 5932f8a7 Load default world spawn areas in consistent order 3a5dc78f Fix confusing migration message appearing on fresh server 516a408f Remove redundant CraftBukkit change for secondary world data 73a2c749 Process conversation input on the main thread. 100c3f07 Cap Objective Score Length 6e842759 Cross World Entity Teleportation 7deba1c6 Check for blank OfflinePlayer Names f2746a5e Descriptive kick reasons instead of Nope! b0212308 Cap Channel Registrations a610dcd8 Identify CraftScheduler threads with useful names Spigot Changes: 19c3c5a5 Rebuild patches
96 lines
4.7 KiB
Diff
96 lines
4.7 KiB
Diff
From 4bec88c9c9d3934730f7c9ef94b409a04c8bcc66 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Fri, 3 Aug 2018 22:47:46 -0400
|
|
Subject: [PATCH] Entity add to world fixes
|
|
|
|
1) Chunk Registration might kill an entity, don't add it to the world if it did!
|
|
|
|
2) By default, entities are added to the world per slice iteration.
|
|
This opens risk of the slices being manipulated during chunk add if an
|
|
EntityAddToWorldEvent spawns an entity into this chunk.
|
|
Fix this by differing entity add to world for all entities at the same time
|
|
|
|
3) If a duplicate entity is attempted to add to the world of an entity, and
|
|
the original entity is dead, overwrite it as the logic does for unloaod queued entities.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
|
index ca236a315..edf4d9130 100644
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
@@ -2,6 +2,8 @@ package net.minecraft.server;
|
|
|
|
// Paper start
|
|
import com.destroystokyo.paper.PaperWorldConfig.DuplicateUUIDMode;
|
|
+
|
|
+import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.UUID;
|
|
// Paper end
|
|
@@ -964,15 +966,16 @@ public class Chunk implements IChunkAccess {
|
|
// Paper end
|
|
|
|
// CraftBukkit start
|
|
- List<Entity> toRemove = new LinkedList<>();
|
|
- this.world.a(entityslice.stream().filter((entity) -> {
|
|
- if (this.needsDecoration && !CraftEventFactory.doEntityAddEventCalling(this.world, entity, CreatureSpawnEvent.SpawnReason.CHUNK_GEN)) { // Only call for new chunks
|
|
- toRemove.add(entity);
|
|
- return false;
|
|
- }
|
|
- return !(entity instanceof EntityHuman);
|
|
- }));
|
|
- entityslice.removeAll(toRemove);
|
|
+ this.world.addChunkEntities(entityslice.stream() // Paper - add all at same time to avoid entities adding to world modifying slice state, skip already added entities (not normal, but can happen)
|
|
+ // Paper start - Inline event into stream
|
|
+ .filter((entity) -> {
|
|
+ if (!this.needsDecoration) {
|
|
+ return true;
|
|
+ }
|
|
+ return CraftEventFactory.doEntityAddEventCalling(this.world, entity, CreatureSpawnEvent.SpawnReason.CHUNK_GEN);
|
|
+ })
|
|
+ // Paper end - Inline event into stream
|
|
+ .filter((entity) -> !(entity instanceof EntityHuman || entity.valid))); // Paper - add all at same time to avoid entities adding to world modifying slice state, skip already added entities (not normal, but can happen)
|
|
// CraftBukkit end
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
|
index 0d112016f..187506b57 100644
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
@@ -1032,6 +1032,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
|
}
|
|
|
|
this.getChunkAt(i, j).a(entity);
|
|
+ if (entity.dead) return false; // Paper - don't add dead entities, chunk registration may of killed it
|
|
this.entityList.add(entity);
|
|
this.b(entity);
|
|
return true;
|
|
@@ -2437,9 +2438,13 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
|
return j;
|
|
}
|
|
|
|
+ public void addChunkEntities(Stream<Entity> collection) { a(collection); } // Paper - OBFHELPER
|
|
public void a(Stream<Entity> stream) {
|
|
org.spigotmc.AsyncCatcher.catchOp( "entity world add"); // Spigot
|
|
stream.forEach((entity) -> {
|
|
+ if (entity == null || entity.dead || entity.valid) { // Paper - prevent adding already added or dead entities
|
|
+ return;
|
|
+ }
|
|
this.entityList.add(entity);
|
|
this.b(entity);
|
|
});
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
|
index a896f8fe4..609be457a 100644
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
|
@@ -968,7 +968,7 @@ public class WorldServer extends World implements IAsyncTaskHandler {
|
|
if (this.entitiesByUUID.containsKey(uuid)) {
|
|
Entity entity1 = (Entity) this.entitiesByUUID.get(uuid);
|
|
|
|
- if (this.g.contains(entity1)) {
|
|
+ if (this.g.contains(entity1) || entity1.dead) { // Paper - if dupe is dead, overwrite
|
|
this.g.remove(entity1);
|
|
} else {
|
|
if (!(entity instanceof EntityHuman)) {
|
|
--
|
|
2.20.1
|
|
|