Trying improve logs in lib paper’s ThreadUtil

This commit is contained in:
Marc Baloup 2021-07-04 18:20:33 +02:00
parent 04148b88b3
commit 807b7ce4ed
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893
1 changed files with 8 additions and 8 deletions

View File

@ -1,7 +1,6 @@
package fr.pandacube.lib.paper.util;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import org.bukkit.Bukkit;
@ -21,13 +20,14 @@ public class ThreadUtil {
if (Bukkit.isPrimaryThread())
return task.call();
try {
return Bukkit.getScheduler().callSyncMethod(PandaLibPaper.getPlugin(), task).get();
} catch (ExecutionException e) {
Log.severe("Execution Exception while running code on server Thread. The source exception is:",
e.getCause());
throw e;
}
return Bukkit.getScheduler().callSyncMethod(PandaLibPaper.getPlugin(), () -> {
try {
return task.call();
} catch (Exception e) {
Log.severe("Exception while running callback code on server Thread. The source exception is:", e);
throw e;
}
}).get();
}
public static void runOnServerThreadAndWait(Runnable task) throws Exception {