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 // Queue for async tasks
private AtomicInteger runningCount = new AtomicInteger(); private AtomicInteger runningCount = new AtomicInteger();
private SimpleAsyncNotifyQueue asyncNotifyQueue = new SimpleAsyncNotifyQueue(new Thread.UncaughtExceptionHandler() { private SimpleAsyncNotifyQueue asyncNotifyQueue = new SimpleAsyncNotifyQueue((t, e) -> {
@Override while (e.getCause() != null) {
public void uncaughtException(Thread t, Throwable e) { e = e.getCause();
while (e.getCause() != null) { }
e = e.getCause(); if (e instanceof WorldEditException) {
} sendMessage(BBC.getPrefix() + e.getLocalizedMessage());
if (e instanceof WorldEditException) { } else {
sendMessage(BBC.getPrefix() + e.getLocalizedMessage()); FaweException fe = FaweException.get(e);
if (fe != null) {
sendMessage(fe.getMessage());
} else { } else {
FaweException fe = FaweException.get(e); e.printStackTrace();
if (fe != null) {
sendMessage(fe.getMessage());
} else {
e.printStackTrace();
}
} }
} }
}); });

View File

@ -4,9 +4,9 @@ import com.boydti.fawe.util.TaskManager;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
public abstract class AsyncNotifyQueue { public abstract class AsyncNotifyQueue {
private Object lock = new Object(); protected Object lock = new Object();
private final Runnable task; protected final Runnable task;
private final AtomicBoolean running = new AtomicBoolean(); protected final AtomicBoolean running = new AtomicBoolean();
public AsyncNotifyQueue() { public AsyncNotifyQueue() {
this.task = new Runnable() { this.task = new Runnable() {
@ -25,7 +25,7 @@ public abstract class AsyncNotifyQueue {
public void queue(Runnable queueTask) { public void queue(Runnable queueTask) {
synchronized (lock) { synchronized (lock) {
queueTask.run(); if (queueTask != null) queueTask.run();
if (!running.get()) { if (!running.get()) {
running.set(true); running.set(true);
TaskManager.IMP.async(task); TaskManager.IMP.async(task);

View File

@ -1,5 +1,7 @@
package com.boydti.fawe.object.task; package com.boydti.fawe.object.task;
import com.boydti.fawe.util.TaskManager;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
public class SimpleAsyncNotifyQueue extends AsyncNotifyQueue { 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() { public int getSize() {
return tasks.size(); return tasks.size();
} }

View File

@ -467,7 +467,7 @@ public final class CommandManager {
public void run() { public void run() {
handleCommandOnCurrentThread(finalEvent); handleCommandOnCurrentThread(finalEvent);
} }
}, true, false)) { }, false, true)) {
BBC.WORLDEDIT_COMMAND_LIMIT.send(fp); BBC.WORLDEDIT_COMMAND_LIMIT.send(fp);
} }
finalEvent.setCancelled(true); finalEvent.setCancelled(true);