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();
try { return Bukkit.getScheduler().callSyncMethod(PandaLibPaper.getPlugin(), () -> {
return Bukkit.getScheduler().callSyncMethod(PandaLibPaper.getPlugin(), task).get(); try {
} catch (ExecutionException e) { return task.call();
Log.severe("Execution Exception while running code on server Thread. The source exception is:", } catch (Exception e) {
e.getCause()); Log.severe("Exception while running callback code on server Thread. The source exception is:", e);
throw e; throw e;
} }
}).get();
} }
public static void runOnServerThreadAndWait(Runnable task) throws Exception { public static void runOnServerThreadAndWait(Runnable task) throws Exception {