2020-05-06 09:44:47 +02:00
|
|
|
From 8a2267af66d0af048717527cfeaf8af8f031e25c 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
|
2020-04-27 09:34:45 +02:00
|
|
|
index b839769cea..5acad8e44f 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
|
2019-08-15 04:47:38 +02:00
|
|
|
@@ -179,6 +179,7 @@ public class PaperCommand extends Command {
|
2020-03-18 13:38:24 +01:00
|
|
|
Collection<Entity> entities = world.entitiesById.values();
|
|
|
|
entities.forEach(e -> {
|
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
|
2020-05-06 09:44:47 +02:00
|
|
|
index 0afa8a7ebd..8e9ddca049 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
|
2020-05-06 09:44:47 +02:00
|
|
|
@@ -810,6 +810,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)) {
|
2020-05-06 09:44:47 +02:00
|
|
|
@@ -847,6 +848,7 @@ public class Chunk implements IChunkAccess {
|
2019-05-05 04:23:25 +02:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
2019-12-12 01:03:31 +01:00
|
|
|
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);
|
2020-05-06 09:44:47 +02:00
|
|
|
@@ -868,6 +870,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
|
2020-04-27 09:34:45 +02:00
|
|
|
index 838aa7da69..35d22ec027 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
|
2020-02-21 18:52:20 +01:00
|
|
|
@@ -195,6 +195,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2019-12-12 01:03:31 +01:00
|
|
|
protected int numCollisions = 0; // Paper
|
|
|
|
public void inactiveTick() { }
|
|
|
|
// Spigot end
|
2019-05-05 04:23:25 +02:00
|
|
|
+ public boolean shouldBeRemoved; // Paper
|
2019-12-12 01:03:31 +01:00
|
|
|
|
|
|
|
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
|
2020-05-06 09:44:47 +02:00
|
|
|
index d1424325d5..f071b61195 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
|
2020-03-19 07:03:32 +01:00
|
|
|
@@ -908,7 +908,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
|
|
|
|
2020-05-06 09:44:47 +02:00
|
|
|
@@ -1242,6 +1242,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
|
|
|
|
}
|
|
|
|
|
2020-05-06 09:44:47 +02:00
|
|
|
@@ -1254,6 +1255,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
|
2020-05-02 00:03:47 +02:00
|
|
|
index cde999c97f..960e29cb16 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
|
2020-05-02 00:03:47 +02:00
|
|
|
@@ -1029,6 +1029,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
|
2020-05-02 00:03:47 +02:00
|
|
|
@@ -1048,6 +1049,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
|
2020-05-02 00:03:47 +02:00
|
|
|
@@ -1074,6 +1076,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) {
|
2020-05-02 00:03:47 +02:00
|
|
|
@@ -1097,6 +1100,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) {
|
|
|
|
--
|
2020-05-06 09:44:47 +02:00
|
|
|
2.26.0
|
2019-05-05 04:23:25 +02:00
|
|
|
|