mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Better method disabling for DataExtension API
This commit is contained in:
parent
e725cc2086
commit
15e7d38043
@ -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"
|
||||
|
@ -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<MethodWrapper> getMethod() {
|
||||
public Optional<MethodWrapper<?>> getMethod() {
|
||||
// method is transient and might be lost if flushed to disk.
|
||||
return Optional.ofNullable(method);
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ public class MethodWrapper<T> {
|
||||
private final Method method;
|
||||
private final Class<T> returnType;
|
||||
private final MethodType methodType;
|
||||
private boolean disabled = false;
|
||||
|
||||
public MethodWrapper(Method method, Class<T> returnType) {
|
||||
this.method = method;
|
||||
@ -42,6 +43,7 @@ public class MethodWrapper<T> {
|
||||
}
|
||||
|
||||
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<T> {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
this.disabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -105,6 +105,7 @@ public class ProviderValueGatherer {
|
||||
}
|
||||
|
||||
public void disableMethodFromUse(MethodWrapper<?> method) {
|
||||
method.disable();
|
||||
dataProviders.removeProviderWithMethod(method);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user