Skip to content

Commit b8fe22c

Browse files
authored
Do not call EntityRemoveEvent during worldgen (#12588)
Ports the follow commits from spigot to paper. All credits to go the respective commit authors listed below. CraftBukkit: 3b4fd5b321f4440a2b3a67f3945739b45e6e687f By: md_5 <[email protected]>
1 parent 220b57a commit b8fe22c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

paper-server/patches/sources/net/minecraft/server/level/ServerLevel.java.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,11 @@
10651065
@Override
10661066
public CrashReportCategory fillReportDetails(CrashReport report) {
10671067
CrashReportCategory crashReportCategory = super.fillReportDetails(report);
1068-
@@ -1712,6 +_,7 @@
1068+
@@ -1712,6 +_,8 @@
10691069
final class EntityCallbacks implements LevelCallback<Entity> {
10701070
@Override
10711071
public void onCreated(Entity entity) {
1072+
+ entity.inWorld = true; // CraftBukkit - Mark entity as in world
10721073
+ entity.setOldPosAndRot(); // Paper - update old pos / rot for new entities as it will default to Vec3.ZERO
10731074
}
10741075

@@ -1108,11 +1109,10 @@
11081109
String string = "onTrackingStart called during navigation iteration";
11091110
Util.logAndPauseIfInIde(
11101111
"onTrackingStart called during navigation iteration", new IllegalStateException("onTrackingStart called during navigation iteration")
1111-
@@ -1755,10 +_,52 @@
1112+
@@ -1755,10 +_,51 @@
11121113
}
11131114

11141115
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
1115-
+ entity.inWorld = true; // CraftBukkit - Mark entity as in world
11161116
+ entity.valid = true; // CraftBukkit
11171117
+ ServerLevel.this.getChunkSource().addEntity(entity); // Paper - ignore and warn about illegal addEntity calls instead of crashing server
11181118
+ // Paper start - Entity origin API

paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,11 @@ public static void callEntityRemoveEvent(Entity entity, EntityRemoveEvent.Cause
19611961
return;
19621962
}
19631963

1964+
// SPIGOT-8041: Do not call event unless entity has been spawned into world
1965+
if (!entity.inWorld) {
1966+
return;
1967+
}
1968+
19641969
Bukkit.getPluginManager().callEvent(new EntityRemoveEvent(entity.getBukkitEntity(), cause));
19651970
}
19661971

0 commit comments

Comments
 (0)