aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0445-Delay-unsafe-actions-until-after-entity-ticking-is-d.patch
blob: e5c08756d6ce64025d87e68634268d540cd6ad46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 8f1a47fcb317fc79f8827e93d9bfe8e9023cca20..8f87e5121631dfa50f6cb95d036a700135d21b2c 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;
@@ -528,6 +538,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;