diff --git a/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java b/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java index 8f3e80e534..7e9efb8058 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java +++ b/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java @@ -24,7 +24,7 @@ import org.apache.commons.lang.Validate; * @param The type of object you provide. This is created in stage 1, and passed to stage 2, 3, and returned if get() is called. * @param The type of callback you provide. You may register many of these to be passed to the provider in stage 3, one at a time. * @param A type of exception you may throw and expect to be handled by the main thread - * @author Wesley Wolfe (c) 2012 + * @author Wesley Wolfe (c) 2012, 2014 */ public final class AsynchronousExecutor { @@ -208,6 +208,7 @@ public final class AsynchronousExecutor { /** * Adds a callback to the parameter provided, adding parameter to the queue if needed. + *

* This should always be synchronous. */ public void add(P parameter, C callback) { @@ -221,6 +222,7 @@ public final class AsynchronousExecutor { /** * This method attempts to skip the waiting period for said parameter. + *

* This should always be synchronous. * @throws IllegalStateException if the parameter is not in the queue anymore, or sometimes if called from asynchronous thread */ @@ -236,14 +238,14 @@ public final class AsynchronousExecutor { * Processes a parameter as if it was in the queue, without ever passing to another thread. */ public T getSkipQueue(P parameter) throws E { - return skipQueue(provider, parameter); + return skipQueue(parameter); } /** * Processes a parameter as if it was in the queue, without ever passing to another thread. */ public T getSkipQueue(P parameter, C callback) throws E { - final T object = skipQueue(provider, parameter); + final T object = skipQueue(parameter); provider.callStage3(parameter, object, callback); return object; } @@ -253,7 +255,7 @@ public final class AsynchronousExecutor { */ public T getSkipQueue(P parameter, C...callbacks) throws E { final CallBackProvider provider = this.provider; - final T object = skipQueue(provider, parameter); + final T object = skipQueue(parameter); for (C callback : callbacks) { provider.callStage3(parameter, object, callback); } @@ -265,14 +267,18 @@ public final class AsynchronousExecutor { */ public T getSkipQueue(P parameter, Iterable callbacks) throws E { final CallBackProvider provider = this.provider; - final T object = skipQueue(provider, parameter); + final T object = skipQueue(parameter); for (C callback : callbacks) { provider.callStage3(parameter, object, callback); } return object; } - private static T skipQueue(CallBackProvider provider, P parameter) throws E { + private T skipQueue(P parameter) throws E { + Task task = tasks.get(parameter); + if (task != null) { + return task.get(); + } T object = provider.callStage1(parameter); provider.callStage2(parameter, object); return object;