3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-17 20:10:10 +01:00
Paper/Spigot-Server-Patches/0321-Process-Chunk.addEntities-before-chunkLoadEvent.patch
Aikar c7dcc8ce89
Merge pull request #1244
3e19de0c Rebuild Patches (BillyGalbreath)
8e5db995 AnvilDamageEvent (BillyGalbreath)

* pull/1244/head:
  Rebuild Patches
  AnvilDamageEvent
2018-07-30 00:12:03 -04:00

72 Zeilen
3.3 KiB
Diff

From a02a1b3c9ef37a959c88e9872d74b9c51ff589b4 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 29 Jul 2018 16:56:48 -0400
Subject: [PATCH] Process Chunk.addEntities before chunkLoadEvent
1.13 undesirably changed behavior here that chunk load event fired
before the entities were added to the world.
This means any plugin that spawns entities in chunk load event
causes the entities to be registered to the chunk, and then
added to the world twice.
Moves Entity Add to World to be done anytime a chunk is
registered to the Chunk Map, and ignore other calls.
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 4e32ae7db6..f0098e910a 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -897,7 +897,8 @@ public class Chunk implements IChunkAccess {
}
- public void addEntities() {
+ public void addEntities() { } // Paper - do nothing if anything calls this, we call it properly during ChunkMap.put
+ public void addEntitiesToWorld() { // Paper - rename to ensure noone else calls it
this.j = true;
this.world.b(this.tileEntities.values());
List[] aentityslice = this.entitySlices; // Spigot
diff --git a/src/main/java/net/minecraft/server/ChunkMap.java b/src/main/java/net/minecraft/server/ChunkMap.java
index 5757aa80f3..c6cedba96e 100644
--- a/src/main/java/net/minecraft/server/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/ChunkMap.java
@@ -31,6 +31,7 @@ public class ChunkMap extends Long2ObjectOpenHashMap<Chunk> {
}
}
}
+ chunk.addEntitiesToWorld(); // Paper - call before ChunkLoadEvent to maintain pre 1.13 order, otherwise CLE can manipulate the chunks entities
org.bukkit.Server server = chunk.world.getServer();
if (server != null) {
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
index bd52bf6561..e27e952a1b 100644
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
@@ -154,8 +154,8 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
if (data != null) {
Chunk chunk = (Chunk) data[0];
NBTTagCompound nbttagcompound = (NBTTagCompound) data[1];
- consumer.accept(chunk);
this.loadEntities(nbttagcompound.getCompound("Level"), chunk);
+ consumer.accept(chunk); // Paper - call AFTER entities are loaded
return chunk;
}
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index ece1871294..4fc3c2c354 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -2464,7 +2464,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
- if (entity == null) {
+ if (entity == null || entity.valid) { // Paper - if already added, skip (shouldn't happen, but safety)
continue;
}
this.entityList.add(entity);
--
2.18.0