Paper/Spigot-Server-Patches/0445-Delay-unsafe-actions-until-after-entity-ticking-is-d.patch
Aikar b6925c36af
Remove no longer needed undead horse leash patch
This is now default vanilla behavior

Fixes #3644
2020-06-28 04:35:41 -04:00

46 lines
2.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 11 Apr 2020 21:23:42 -0400
Subject: [PATCH] Delay unsafe actions until after entity ticking is done
This will help prevent many cases of unregistering entities during entity ticking
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 2cc9fd7aee91cc78156fc6001f0c461530a7f882..00df3260d4f208052515fcd2613be1d6f92e7b1f 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -61,6 +61,16 @@ public class WorldServer extends World implements GeneratorAccessSeed {
public final List<EntityPlayer> players = Lists.newArrayList(); // Paper - private -> public
public final ChunkProviderServer chunkProvider; // Paper - public
boolean tickingEntities;
+ // Paper start
+ List<java.lang.Runnable> afterEntityTickingTasks = Lists.newArrayList();
+ public void doIfNotEntityTicking(java.lang.Runnable run) {
+ if (tickingEntities) {
+ afterEntityTickingTasks.add(run);
+ } else {
+ run.run();
+ }
+ }
+ // Paper end
private final MinecraftServer server;
public final WorldDataServer worldDataServer; // CraftBukkit - type
public boolean savingDisabled;
@@ -529,6 +539,16 @@ public class WorldServer extends World implements GeneratorAccessSeed {
timings.entityTick.stopTiming(); // Spigot
this.tickingEntities = false;
+ // Paper start
+ for (java.lang.Runnable run : this.afterEntityTickingTasks) {
+ try {
+ run.run();
+ } catch (Exception e) {
+ LOGGER.error("Error in After Entity Ticking Task", e);
+ }
+ }
+ this.afterEntityTickingTasks.clear();
+ // Paper end
this.getMinecraftServer().midTickLoadChunks(); // Paper
Entity entity2;