2020-05-02 00:03:47 +02:00
|
|
|
From f6bbc419402487cc17d4788ab2c10812abe20e24 Mon Sep 17 00:00:00 2001
|
2020-04-12 03:31:40 +02:00
|
|
|
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
|
2020-04-26 10:01:03 +02:00
|
|
|
index dc01fb494d..d13dc8fce9 100644
|
2020-04-12 03:31:40 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
|
|
|
@@ -60,6 +60,16 @@ public class WorldServer extends World {
|
|
|
|
private final Queue<Entity> entitiesToAdd = Queues.newArrayDeque();
|
|
|
|
public final List<EntityPlayer> players = Lists.newArrayList(); // Paper - private -> 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;
|
|
|
|
private final WorldNBTStorage dataManager;
|
|
|
|
public boolean savingDisabled;
|
2020-04-26 10:01:03 +02:00
|
|
|
@@ -531,6 +541,16 @@ public class WorldServer extends World {
|
2020-04-12 03:31:40 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
try (co.aikar.timings.Timing ignored = this.timings.newEntities.startTiming()) { // Paper - timings
|
|
|
|
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 eb7b48422e..ac257d50de 100644
|
2020-04-12 03:31:40 +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
|
|
|
@@ -2473,7 +2473,7 @@ public class CraftWorld implements World {
|
2020-04-12 03:31:40 +02:00
|
|
|
|
|
|
|
CompletableFuture<Chunk> ret = new CompletableFuture<>();
|
|
|
|
this.world.getChunkProvider().getChunkAtAsynchronously(x, z, gen, (net.minecraft.server.Chunk chunk) -> {
|
|
|
|
- ret.complete(chunk == null ? null : chunk.bukkitChunk);
|
|
|
|
+ this.world.doIfNotEntityTicking(() -> ret.complete(chunk == null ? null : chunk.bukkitChunk));
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
--
|
2020-04-26 10:01:03 +02:00
|
|
|
2.26.2
|
2020-04-12 03:31:40 +02:00
|
|
|
|