diff --git a/common/server/src/main/java/com/discordsrv/common/server/ServerDiscordSRV.java b/common/server/src/main/java/com/discordsrv/common/server/ServerDiscordSRV.java index 92fa89e6..7e8e639d 100644 --- a/common/server/src/main/java/com/discordsrv/common/server/ServerDiscordSRV.java +++ b/common/server/src/main/java/com/discordsrv/common/server/ServerDiscordSRV.java @@ -37,13 +37,7 @@ public abstract class ServerDiscordSRV playerProvider(); public final CompletableFuture invokeServerStarted() { - return CompletableFuture.runAsync(() -> { - try { - serverStarted(); - } catch (Throwable t) { - logger().error("Failed to enable", t); - } - }, scheduler().executor()); + return invoke(this::serverStarted, "Failed to enable", true); } @OverridingMethodsMustInvokeSuper diff --git a/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java b/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java index d3c71e4f..6a4cd78a 100644 --- a/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java +++ b/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java @@ -78,9 +78,7 @@ public abstract class AbstractDiscordSRV invoke(CheckedRunnable runnable, String message) { + protected CompletableFuture invoke(CheckedRunnable runnable, String message, boolean enable) { return CompletableFuture.runAsync(() -> { try { runnable.run(); } catch (Throwable t) { - setStatus(Status.FAILED_TO_START); - disable(); + if (enable) { + setStatus(Status.FAILED_TO_START); + disable(); + } logger().error(message, t); } }, scheduler().executor()); @@ -169,17 +169,17 @@ public abstract class AbstractDiscordSRV invokeEnable() { - return invoke(this::enable, "Failed to enable"); + return invoke(this::enable, "Failed to enable", true); } @Override public final CompletableFuture invokeDisable() { - return invoke(this::disable, "Failed to disable"); + return invoke(this::disable, "Failed to disable", false); } @Override public final CompletableFuture invokeReload() { - return invoke(this::reload, "Failed to reload"); + return invoke(this::reload, "Failed to reload", false); } @OverridingMethodsMustInvokeSuper @@ -214,16 +214,12 @@ public abstract class AbstractDiscordSRV