From d3696f91d46e1c5b350403d2a819a2e42cf1dacf Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 15 Jan 2022 17:09:49 +0000 Subject: [PATCH] Synchronise access to the PriorityQueue used for effect queuing in AbstractWorld - Makes it thread-safe --- .../sk89q/worldedit/world/AbstractWorld.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java index 53b47bbae..28ca13736 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java @@ -111,14 +111,18 @@ public abstract class AbstractWorld implements World { public boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority) { if (taskId == -1) { taskId = server.schedule(0, 1, () -> { - int max = Math.max(1, Math.min(30, effectQueue.size() / 3)); - for (int i = 0; i < max; ++i) { - if (effectQueue.isEmpty()) { - return; - } + //FAWE start - access to PriorityQueue is not thread-safe + synchronized (effectQueue) { + int max = Math.max(1, Math.min(30, effectQueue.size() / 3)); + for (int i = 0; i < max; ++i) { + if (effectQueue.isEmpty()) { + return; + } - effectQueue.poll().play(); + effectQueue.poll().play(); + } } + //FAWE end }); } @@ -126,7 +130,11 @@ public abstract class AbstractWorld implements World { return false; } - effectQueue.offer(new QueuedEffect(position.toVector3(), blockType, priority)); + //FAWE start - access to PriorityQueue is not thread-safe + synchronized (effectQueue) { + effectQueue.offer(new QueuedEffect(position.toVector3(), blockType, priority)); + } + //FAWE end return true; }