diff --git a/build.gradle b/build.gradle index 32ff55a2..c795bf80 100644 --- a/build.gradle +++ b/build.gradle @@ -110,5 +110,6 @@ subprojects { maven {url "http://maven.sk89q.com/artifactory/repo"} maven {url "http://repo.spongepowered.org/maven"} maven {url "https://repo.inventivetalent.org/content/groups/public/"} + maven {url "http://dl.bintray.com/tastybento/maven-repo"} } } diff --git a/bukkit/build.gradle b/bukkit/build.gradle index 6439afe9..5fa673b0 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -1,6 +1,5 @@ repositories { flatDir {dirs 'lib'} - maven {url "http://dl.bintray.com/tastybento/maven-repo"} } dependencies { compile project(':core') diff --git a/core/src/main/java/com/boydti/fawe/util/TaskManager.java b/core/src/main/java/com/boydti/fawe/util/TaskManager.java index 188f6856..683a2c49 100644 --- a/core/src/main/java/com/boydti/fawe/util/TaskManager.java +++ b/core/src/main/java/com/boydti/fawe/util/TaskManager.java @@ -9,6 +9,7 @@ import java.util.Iterator; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; import javax.annotation.Nullable; public abstract class TaskManager { @@ -284,6 +285,10 @@ public abstract class TaskManager { return sync(function, Integer.MAX_VALUE); } + public T sync(final Supplier function) { + return sync(function, Integer.MAX_VALUE); + } + public void wait(AtomicBoolean running, int timout) { try { long start = System.currentTimeMillis(); @@ -380,16 +385,19 @@ public abstract class TaskManager { * @return */ public T sync(final RunnableVal function, int timeout) { + return sync((Supplier) function, timeout); + } + + public T sync(final Supplier function, int timeout) { if (Fawe.get().getMainThread() == Thread.currentThread()) { - function.run(); - return function.value; + return function.get(); } final AtomicBoolean running = new AtomicBoolean(true); - RunnableVal run = new RunnableVal() { + RunnableVal run = new RunnableVal() { @Override - public void run(RuntimeException value) { + public void run(Object value) { try { - function.run(); + this.value = function.get(); } catch (RuntimeException e) { this.value = e; } catch (Throwable neverHappens) { @@ -412,9 +420,9 @@ public abstract class TaskManager { } catch (InterruptedException e) { MainUtil.handleError(e); } - if (run.value != null) { - throw run.value; + if (run.value != null && run.value instanceof RuntimeException) { + throw (RuntimeException) run.value; } - return function.value; + return (T) run.value; } }