From 7eb83c000b07ff0cf0c5f0a88ea79b8d7d127f58 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 23 May 2018 16:34:38 +1000 Subject: [PATCH] Fix command queuing from console --- .../com/boydti/fawe/object/FawePlayer.java | 25 ++++++++----------- .../fawe/object/task/AsyncNotifyQueue.java | 8 +++--- .../object/task/SimpleAsyncNotifyQueue.java | 12 +++++++++ .../extension/platform/CommandManager.java | 2 +- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java index 53e1d265..c4fb4a49 100644 --- a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -269,21 +269,18 @@ public abstract class FawePlayer extends Metadatable { // Queue for async tasks private AtomicInteger runningCount = new AtomicInteger(); - private SimpleAsyncNotifyQueue asyncNotifyQueue = new SimpleAsyncNotifyQueue(new Thread.UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread t, Throwable e) { - while (e.getCause() != null) { - e = e.getCause(); - } - if (e instanceof WorldEditException) { - sendMessage(BBC.getPrefix() + e.getLocalizedMessage()); + private SimpleAsyncNotifyQueue asyncNotifyQueue = new SimpleAsyncNotifyQueue((t, e) -> { + while (e.getCause() != null) { + e = e.getCause(); + } + if (e instanceof WorldEditException) { + sendMessage(BBC.getPrefix() + e.getLocalizedMessage()); + } else { + FaweException fe = FaweException.get(e); + if (fe != null) { + sendMessage(fe.getMessage()); } else { - FaweException fe = FaweException.get(e); - if (fe != null) { - sendMessage(fe.getMessage()); - } else { - e.printStackTrace(); - } + e.printStackTrace(); } } }); diff --git a/core/src/main/java/com/boydti/fawe/object/task/AsyncNotifyQueue.java b/core/src/main/java/com/boydti/fawe/object/task/AsyncNotifyQueue.java index c7ac30bc..5cce6b0f 100644 --- a/core/src/main/java/com/boydti/fawe/object/task/AsyncNotifyQueue.java +++ b/core/src/main/java/com/boydti/fawe/object/task/AsyncNotifyQueue.java @@ -4,9 +4,9 @@ import com.boydti.fawe.util.TaskManager; import java.util.concurrent.atomic.AtomicBoolean; public abstract class AsyncNotifyQueue { - private Object lock = new Object(); - private final Runnable task; - private final AtomicBoolean running = new AtomicBoolean(); + protected Object lock = new Object(); + protected final Runnable task; + protected final AtomicBoolean running = new AtomicBoolean(); public AsyncNotifyQueue() { this.task = new Runnable() { @@ -25,7 +25,7 @@ public abstract class AsyncNotifyQueue { public void queue(Runnable queueTask) { synchronized (lock) { - queueTask.run(); + if (queueTask != null) queueTask.run(); if (!running.get()) { running.set(true); TaskManager.IMP.async(task); diff --git a/core/src/main/java/com/boydti/fawe/object/task/SimpleAsyncNotifyQueue.java b/core/src/main/java/com/boydti/fawe/object/task/SimpleAsyncNotifyQueue.java index b3cc2c05..3b56d1dc 100644 --- a/core/src/main/java/com/boydti/fawe/object/task/SimpleAsyncNotifyQueue.java +++ b/core/src/main/java/com/boydti/fawe/object/task/SimpleAsyncNotifyQueue.java @@ -1,5 +1,7 @@ package com.boydti.fawe.object.task; +import com.boydti.fawe.util.TaskManager; + import java.util.concurrent.ConcurrentLinkedQueue; public class SimpleAsyncNotifyQueue extends AsyncNotifyQueue { @@ -27,6 +29,16 @@ public class SimpleAsyncNotifyQueue extends AsyncNotifyQueue { } } + public void queue(Runnable queueTask) { + synchronized (lock) { + if (queueTask != null) tasks.add(queueTask); + if (!running.get()) { + running.set(true); + TaskManager.IMP.async(task); + } + } + } + public int getSize() { return tasks.size(); } diff --git a/core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java b/core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java index e013cfbd..e65bc1b8 100644 --- a/core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java +++ b/core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java @@ -467,7 +467,7 @@ public final class CommandManager { public void run() { handleCommandOnCurrentThread(finalEvent); } - }, true, false)) { + }, false, true)) { BBC.WORLDEDIT_COMMAND_LIMIT.send(fp); } finalEvent.setCancelled(true);