diff --git a/Spigot-Server-Patches/0491-Allow-multiple-callbacks-to-schedule-for-Callback-Ex.patch b/Spigot-Server-Patches/0491-Allow-multiple-callbacks-to-schedule-for-Callback-Ex.patch new file mode 100644 index 000000000..1c0679aae --- /dev/null +++ b/Spigot-Server-Patches/0491-Allow-multiple-callbacks-to-schedule-for-Callback-Ex.patch @@ -0,0 +1,52 @@ +From 429c6c3f9e55451e7f2e0065879884f3e0e13217 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Tue, 21 Apr 2020 03:51:53 -0400 +Subject: [PATCH] Allow multiple callbacks to schedule for Callback Executor + +ChunkMapDistance polls multiple entries for pendingChunkUpdates + +Each of these have the potential to move a chunk in and out of +"Loaded" state, which will result in multiple callbacks being +needed within a single tick of ChunkMapDistance + +Use an ArrayDeque to store this Queue + +diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java +index 8b2eed1051..ee0cabadc8 100644 +--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java ++++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java +@@ -87,25 +87,22 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { + public final CallbackExecutor callbackExecutor = new CallbackExecutor(); + public static final class CallbackExecutor implements java.util.concurrent.Executor, Runnable { + +- private Runnable queued; ++ // Paper start - replace impl with Deque - possible multiple is needed in single pass ++ private java.util.Deque queued = new java.util.ArrayDeque<>(); + + @Override + public void execute(Runnable runnable) { +- if (queued != null) { +- MinecraftServer.LOGGER.fatal("Failed to schedule runnable", new IllegalStateException("Already queued")); // Paper - make sure this is printed +- throw new IllegalStateException("Already queued"); +- } +- queued = runnable; ++ queued.add(runnable); // Paper + } + + @Override + public void run() { +- Runnable task = queued; +- queued = null; +- if (task != null) { ++ Runnable task; ++ while ((task = queued.pollFirst()) != null) { + task.run(); + } + } ++ // Paper end + }; + // CraftBukkit end + +-- +2.25.1 +