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

View File

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