From 15e7d38043f0a5209fa3c92691652cdfbc5c54c2 Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+Rsl1122@users.noreply.github.com> Date: Sat, 23 May 2020 12:13:11 +0300 Subject: [PATCH] Better method disabling for DataExtension API --- Plan/common/build.gradle | 1 + .../plan/exceptions/DataExtensionMethodCallException.java | 6 +++--- .../extension/implementation/providers/MethodWrapper.java | 6 ++++++ .../providers/gathering/ProviderValueGatherer.java | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Plan/common/build.gradle b/Plan/common/build.gradle index 1b6bd80dd..2782a159a 100644 --- a/Plan/common/build.gradle +++ b/Plan/common/build.gradle @@ -1,6 +1,7 @@ dependencies { compile "com.djrapitops:AbstractPluginFramework-api:$abstractPluginFrameworkVersion" compile project(":api") + compileOnly project(":extensions") compile project(path: ":extensions", configuration: 'shadow') compile "org.apache.httpcomponents:httpclient:$httpClientVersion" compile "org.apache.commons:commons-text:$commonsTextVersion" diff --git a/Plan/common/src/main/java/com/djrapitops/plan/exceptions/DataExtensionMethodCallException.java b/Plan/common/src/main/java/com/djrapitops/plan/exceptions/DataExtensionMethodCallException.java index a504f386c..0f1816fae 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/exceptions/DataExtensionMethodCallException.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/exceptions/DataExtensionMethodCallException.java @@ -29,9 +29,9 @@ public class DataExtensionMethodCallException extends IllegalStateException { private final String pluginName; // Non serializable field due to Method not being serializable. - private final transient MethodWrapper method; + private final transient MethodWrapper method; - public DataExtensionMethodCallException(Throwable cause, String pluginName, MethodWrapper method) { + public DataExtensionMethodCallException(Throwable cause, String pluginName, MethodWrapper method) { super(cause); this.pluginName = pluginName; this.method = method; @@ -41,7 +41,7 @@ public class DataExtensionMethodCallException extends IllegalStateException { return pluginName; } - public Optional getMethod() { + public Optional> getMethod() { // method is transient and might be lost if flushed to disk. return Optional.ofNullable(method); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java index 8fdedf90d..070bae8ce 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java @@ -34,6 +34,7 @@ public class MethodWrapper { private final Method method; private final Class returnType; private final MethodType methodType; + private boolean disabled = false; public MethodWrapper(Method method, Class returnType) { this.method = method; @@ -42,6 +43,7 @@ public class MethodWrapper { } public T callMethod(DataExtension extension, Parameters with) { + if (disabled) return null; try { return returnType.cast(with.usingOn(extension, method)); } catch (InvocationTargetException notReadyToBeCalled) { @@ -67,6 +69,10 @@ public class MethodWrapper { return returnType; } + public void disable() { + this.disabled = true; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/ProviderValueGatherer.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/ProviderValueGatherer.java index 5a5691532..3519a8c62 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/ProviderValueGatherer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/ProviderValueGatherer.java @@ -105,6 +105,7 @@ public class ProviderValueGatherer { } public void disableMethodFromUse(MethodWrapper method) { + method.disable(); dataProviders.removeProviderWithMethod(method); }