Paper/Spigot-Server-Patches/0264-Ignore-Dead-Entities-in-entityList-iteration.patch

133 lines
6.7 KiB
Diff
Raw Normal View History

From 1f36f26c18a57565356f9a8514cc467d7b0094d5 Mon Sep 17 00:00:00 2001
2019-05-05 04:23:25 +02:00
From: Aikar <aikar@aikar.co>
Date: Sat, 28 Jul 2018 12:18:27 -0400
Subject: [PATCH] Ignore Dead Entities in entityList iteration
A spigot change delays removal of entities from the entity list.
This causes a change in behavior from Vanilla where getEntities type
methods will return dead entities that they shouldn't otherwise be doing.
This will ensure that dead entities are skipped from iteration since
they shouldn't of been in the list in the first place.
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
index eecf27370b..d704fc79c0 100644
2019-05-05 04:23:25 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
@@ -179,6 +179,7 @@ public class PaperCommand extends Command {
return;
}
2019-05-05 04:23:25 +02:00
MinecraftKey key = e.getMinecraftKey();
+ if (e.shouldBeRemoved) return; // Paper
MutablePair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap()));
ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.getChunkX(), e.getChunkZ());
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 1d47e47370..c464d69623 100644
2019-05-05 04:23:25 +02:00
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -681,6 +681,7 @@ public class Chunk implements IChunkAccess {
2019-05-05 04:23:25 +02:00
while (iterator.hasNext()) {
Entity entity1 = (Entity) iterator.next();
+ if (entity1.shouldBeRemoved) continue; // Paper
if (entity1.getBoundingBox().c(axisalignedbb) && entity1 != entity) {
if (predicate == null || predicate.test(entity1)) {
@@ -718,6 +719,7 @@ public class Chunk implements IChunkAccess {
2019-05-05 04:23:25 +02:00
while (iterator.hasNext()) {
T entity = (T) iterator.next(); // CraftBukkit - decompile error
2019-05-05 04:23:25 +02:00
+ if (entity.shouldBeRemoved) continue; // Paper
if ((entitytypes == null || entity.getEntityType() == entitytypes) && entity.getBoundingBox().c(axisalignedbb) && predicate.test(entity)) {
list.add(entity);
@@ -739,6 +741,7 @@ public class Chunk implements IChunkAccess {
2019-05-05 04:23:25 +02:00
while (iterator.hasNext()) {
T t0 = (T) iterator.next(); // CraftBukkit - decompile error
+ if (t0.shouldBeRemoved) continue; // Paper
if (oclass.isInstance(t0) && t0.getBoundingBox().c(axisalignedbb) && (predicate == null || predicate.test(t0))) { // Spigot - instance check
list.add(t0);
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index ace74179ce..5d9d32ea45 100644
2019-05-05 04:23:25 +02:00
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -195,6 +195,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
protected int numCollisions = 0; // Paper
public void inactiveTick() { }
// Spigot end
2019-05-05 04:23:25 +02:00
+ public boolean shouldBeRemoved; // Paper
public float getBukkitYaw() {
return this.yaw;
2019-05-05 04:23:25 +02:00
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 70e4b58a93..54505e056e 100644
2019-05-05 04:23:25 +02:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -904,7 +904,7 @@ public class WorldServer extends World {
2019-05-05 04:23:25 +02:00
while (objectiterator.hasNext()) {
Entity entity = (Entity) objectiterator.next();
2019-07-20 06:01:24 +02:00
-
2019-05-05 04:23:25 +02:00
+ if (entity.shouldBeRemoved) continue; // Paper
if (entity instanceof EntityInsentient) {
EntityInsentient entityinsentient = (EntityInsentient) entity;
2019-07-20 06:01:24 +02:00
@@ -1225,6 +1225,7 @@ public class WorldServer extends World {
2019-05-05 23:39:51 +02:00
entity.origin = entity.getBukkitEntity().getLocation();
2019-05-05 04:23:25 +02:00
}
2019-05-05 23:39:51 +02:00
// Paper end
2019-05-05 04:23:25 +02:00
+ entity.shouldBeRemoved = false; // Paper - shouldn't be removed after being re-added
new com.destroystokyo.paper.event.entity.EntityAddToWorldEvent(entity.getBukkitEntity()).callEvent(); // Paper - fire while valid
}
@@ -1237,6 +1238,7 @@ public class WorldServer extends World {
2019-05-05 04:23:25 +02:00
this.removeEntityFromChunk(entity);
this.entitiesById.remove(entity.getId());
this.unregisterEntity(entity);
+ entity.shouldBeRemoved = true; // Paper
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index f957d42723..a6a273c31b 100644
2019-05-05 04:23:25 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1021,6 +1021,7 @@ public class CraftWorld implements World {
2019-05-05 04:23:25 +02:00
for (Object o : world.entitiesById.values()) {
if (o instanceof net.minecraft.server.Entity) {
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity) o;
+ if (mcEnt.shouldBeRemoved) continue; // Paper
Entity bukkitEntity = mcEnt.getBukkitEntity();
// Assuming that bukkitEntity isn't null
@@ -1040,6 +1041,7 @@ public class CraftWorld implements World {
2019-05-05 04:23:25 +02:00
for (Object o : world.entitiesById.values()) {
if (o instanceof net.minecraft.server.Entity) {
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity) o;
+ if (mcEnt.shouldBeRemoved) continue; // Paper
Entity bukkitEntity = mcEnt.getBukkitEntity();
// Assuming that bukkitEntity isn't null
@@ -1066,6 +1068,7 @@ public class CraftWorld implements World {
2019-05-05 04:23:25 +02:00
for (Object entity: world.entitiesById.values()) {
if (entity instanceof net.minecraft.server.Entity) {
+ if (((net.minecraft.server.Entity) entity).shouldBeRemoved) continue; // Paper
Entity bukkitEntity = ((net.minecraft.server.Entity) entity).getBukkitEntity();
if (bukkitEntity == null) {
@@ -1089,6 +1092,7 @@ public class CraftWorld implements World {
2019-05-05 04:23:25 +02:00
for (Object entity: world.entitiesById.values()) {
if (entity instanceof net.minecraft.server.Entity) {
+ if (((net.minecraft.server.Entity) entity).shouldBeRemoved) continue; // Paper
Entity bukkitEntity = ((net.minecraft.server.Entity) entity).getBukkitEntity();
if (bukkitEntity == null) {
--
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: 93e39ce1 Clarify documentation regarding getMaterial with legacyName = true c3aeaea0 Improve dependency tracker 14c9d275 Add support for transitive depends in load access warning c8afe560 SPIGOT-5526: Add EntityEnterBlockEvent 6bb6f07d SPIGOT-5548: Show error that hints towards plugins misusing reflection ed75537d SPIGOT-5546: Fix bad depend access using wrong provider in message 4e4c0ee9 Fix buggy classloader warning triggering for all classes 89586a4c Print warning when loading classes from depends that have not been specified d4fe9680 Fix bug where disablePlugin could remove ConfigurationSerializable classes from other plugins 85e683b7 Add additional checkstyle checks 612fd8e1 Correct max page count in BookMeta docs fa8a9781 Correct max title length in BookMeta docs CraftBukkit Changes: ab13a117 SPIGOT-5550: Cancelled ProjectileLaunchEvent still plays sound for eggs 44016b1d SPIGOT-5538: Using javaw to run GUI prints input error e653ae76 SPIGOT-5526: Call EntityEnterBlockEvent for bees trying to enter hives 6515ea49 SPIGOT-5537: Bee nests generated by growing trees near flower have no bees d82b3149 Remove unused CraftWorld.getId method 10763a88 Change some block == AIR checks to isAir to catch CAVE_AIR Spigot Changes: f2c1cd15 Rebuild patches bcd458ad Reformat patches
2020-01-28 20:43:57 +01:00
2.25.0
2019-05-05 04:23:25 +02:00