Fix command queuing from console

This commit is contained in:
Jesse Boyd 2018-05-23 16:34:38 +10:00
parent cf27decdb4
commit 7eb83c000b
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 28 additions and 19 deletions

View File

@ -269,21 +269,18 @@ public abstract class FawePlayer<T> 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();
}
}
});

View File

@ -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);

View File

@ -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();
}

View File

@ -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);