From c548856b76596e0d83c3d21a9ca1afded415e4b9 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 13 Aug 2022 16:12:32 +0200 Subject: [PATCH] Fix SchedulerUtil exception handling --- .../lib/paper/scheduler/SchedulerUtil.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/scheduler/SchedulerUtil.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/scheduler/SchedulerUtil.java index 7a7ae87..643962c 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/scheduler/SchedulerUtil.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/scheduler/SchedulerUtil.java @@ -1,14 +1,12 @@ package fr.pandacube.lib.paper.scheduler; +import fr.pandacube.lib.paper.PandaLibPaper; +import org.bukkit.Bukkit; + import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; -import org.bukkit.Bukkit; - -import fr.pandacube.lib.util.Log; -import fr.pandacube.lib.paper.PandaLibPaper; - /** * Provides methods to easily manage synchronous and asynchronous operations with the server thread. */ @@ -41,17 +39,15 @@ public class SchedulerUtil { * @throws InterruptedException – if the current thread was interrupted while waiting */ public static T runOnServerThreadAndWait(Callable task) throws Exception { - if (Bukkit.isPrimaryThread()) - return task.call(); - - return Bukkit.getScheduler().callSyncMethod(PandaLibPaper.getPlugin(), () -> { + if (Bukkit.isPrimaryThread()) { try { return task.call(); } catch (Exception e) { - Log.severe("Exception while running callback code on server Thread. The source exception is:", e); - throw e; + throw new ExecutionException(e); } - }).get(); + } + + return Bukkit.getScheduler().callSyncMethod(PandaLibPaper.getPlugin(), task).get(); } /**