From 0f4ba3f787e0860be4e312a4eaaa2a9556624bf8 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 8b2eed10..ee0cabad 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.windows.1