diff --git a/Plan/common/src/main/java/com/djrapitops/plan/PlanSystem.java b/Plan/common/src/main/java/com/djrapitops/plan/PlanSystem.java index 9392e3fb9..94a181684 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/PlanSystem.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/PlanSystem.java @@ -222,6 +222,9 @@ public class PlanSystem implements SubSystem { public void disable() { enabled = false; Formatters.clearSingleton(); + + extensionService.disableUpdates(); + disableSystems( taskSystem, cacheSystem, diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionSvc.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionSvc.java index 135d7bcf4..a72d60770 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionSvc.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionSvc.java @@ -39,6 +39,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; /** * Implementation for {@link ExtensionService}. @@ -58,6 +59,7 @@ public class ExtensionSvc implements ExtensionService { private final ErrorLogger errorLogger; private final Map extensionGatherers; + private final AtomicBoolean enabled; @Inject public ExtensionSvc( @@ -80,6 +82,7 @@ public class ExtensionSvc implements ExtensionService { this.errorLogger = errorLogger; extensionGatherers = new HashMap<>(); + enabled = new AtomicBoolean(true); } public void register() { @@ -152,12 +155,14 @@ public class ExtensionSvc implements ExtensionService { } public void updatePlayerValues(UUID playerUUID, String playerName, CallEvents event) { + if (!enabled.get()) return; // Plugin is disabling for (DataValueGatherer gatherer : extensionGatherers.values()) { updatePlayerValues(gatherer, playerUUID, playerName, event); } } public void updatePlayerValues(DataValueGatherer gatherer, UUID playerUUID, String playerName, CallEvents event) { + if (!enabled.get()) return; // Plugin is disabling if (gatherer.shouldSkipEvent(event)) return; if (playerUUID == null && playerName == null) return; @@ -172,14 +177,20 @@ public class ExtensionSvc implements ExtensionService { } public void updateServerValues(CallEvents event) { + if (!enabled.get()) return; // Plugin is disabling for (DataValueGatherer gatherer : extensionGatherers.values()) { updateServerValues(gatherer, event); } } public void updateServerValues(DataValueGatherer gatherer, CallEvents event) { + if (!enabled.get()) return; // Plugin is disabling if (gatherer.shouldSkipEvent(event)) return; gatherer.updateValues(); } + + public void disableUpdates() { + enabled.set(false); + } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/DataValueGatherer.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/DataValueGatherer.java index 8a479007b..593c7e267 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/DataValueGatherer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/DataValueGatherer.java @@ -49,6 +49,7 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; import java.util.UUID; +import java.util.concurrent.RejectedExecutionException; /** * Object that can be called to place data about players to the database. @@ -293,6 +294,14 @@ public class DataValueGatherer { } public void updateValues(UUID playerUUID, String playerName) { + try { + tryToUpdateValues(playerUUID, playerName); + } catch (RejectedExecutionException ignore) { + // Database has shut down + } + } + + private void tryToUpdateValues(UUID playerUUID, String playerName) { Parameters parameters = Parameters.player(serverInfo.getServerUUID(), playerUUID, playerName); ExtensionDataBuilder dataBuilder = extension.getExtension().newExtensionDataBuilder(); @@ -305,6 +314,14 @@ public class DataValueGatherer { } public void updateValues() { + try { + tryToUpdateValues(); + } catch (RejectedExecutionException ignore) { + // Database has shut down + } + } + + private void tryToUpdateValues() { Parameters parameters = Parameters.server(serverInfo.getServerUUID()); ExtensionDataBuilder dataBuilder = extension.getExtension().newExtensionDataBuilder(); @@ -362,15 +379,19 @@ public class DataValueGatherer { private void logFailure(Throwable cause, String pluginName, String methodName) { ErrorContext.Builder context = ErrorContext.builder() - .whatToDo("Report and/or disable " + pluginName + " extension in the Plan config.") + .whatToDo(getWhatToDoMessage(pluginName)) .related(pluginName) .related("Method:" + methodName); errorLogger.warn(cause, context.build()); } + private String getWhatToDoMessage(String pluginName) { + return "Report and/or disable " + pluginName + " extension in the Plan config."; + } + private void logFailure(DataExtensionMethodCallException methodCallFailed) { ErrorContext.Builder context = ErrorContext.builder() - .whatToDo("Report and/or disable " + methodCallFailed.getPluginName() + " extension in the Plan config.") + .whatToDo(getWhatToDoMessage(methodCallFailed.getPluginName())) .related(methodCallFailed.getPluginName()) .related("Method:" + methodCallFailed.getMethodName().orElse("-")); errorLogger.warn(methodCallFailed, context.build()); @@ -378,7 +399,7 @@ public class DataValueGatherer { private void logFailure(Throwable unexpectedError) { ErrorContext.Builder context = ErrorContext.builder() - .whatToDo("Report and/or disable " + extension.getPluginName() + " extension in the Plan config.") + .whatToDo(getWhatToDoMessage(extension.getPluginName())) .related(extension.getPluginName()); errorLogger.warn(unexpectedError, context.build()); }