diff --git a/Plan/api/build.gradle b/Plan/api/build.gradle index be4217462..7c7e66c82 100644 --- a/Plan/api/build.gradle +++ b/Plan/api/build.gradle @@ -4,7 +4,7 @@ dependencies { compileOnly "com.google.code.gson:gson:$gsonVersion" } -ext.apiVersion = '5.2-R0.5' +ext.apiVersion = '5.2-R0.6' publishing { repositories { diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/builder/ExtensionDataBuilder.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/builder/ExtensionDataBuilder.java index ffdcabe05..209b457ce 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/builder/ExtensionDataBuilder.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/builder/ExtensionDataBuilder.java @@ -72,6 +72,14 @@ public interface ExtensionDataBuilder { */ ExtensionDataBuilder addValue(Class ofType, Supplier> dataValue); + /** + * Invalidate a value similar to {@link com.djrapitops.plan.extension.annotation.InvalidateMethod} annotation, but with the text given to {@link ExtensionDataBuilder#valueBuilder(String)}. + * + * @param text The same text that was given to the value builder. + * @return This builder. + */ + ExtensionDataBuilder invalidateValue(String text); + /** * Add a table. * diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/builder/ExtDataBuilder.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/builder/ExtDataBuilder.java index 2fa5075ee..8c40e108e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/builder/ExtDataBuilder.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/builder/ExtDataBuilder.java @@ -28,12 +28,15 @@ import java.util.function.Supplier; public class ExtDataBuilder implements ExtensionDataBuilder { - private final List values; private final DataExtension extension; + private final List values; + private final Set invalidatedValues; + public ExtDataBuilder(DataExtension extension) { this.extension = extension; values = new ArrayList<>(); + invalidatedValues = new HashSet<>(); } @Override @@ -59,6 +62,12 @@ public class ExtDataBuilder implements ExtensionDataBuilder { return this; } + @Override + public ExtensionDataBuilder invalidateValue(String text) { + invalidatedValues.add(ExtValueBuilder.formatTextAsIdentifier(text)); + return this; + } + public List getValues() { Collections.sort(values); return values; @@ -80,6 +89,10 @@ public class ExtDataBuilder implements ExtensionDataBuilder { this.values.addAll(((ExtDataBuilder) builder).values); } + public Set getInvalidatedValues() { + return invalidatedValues; + } + public static final class ClassValuePair implements Comparable { private final Class type; private final DataValue value; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/builder/ExtValueBuilder.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/builder/ExtValueBuilder.java index 7af5b4060..ec317d8b1 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/builder/ExtValueBuilder.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/builder/ExtValueBuilder.java @@ -52,6 +52,10 @@ public class ExtValueBuilder implements ValueBuilder { pluginName = extension.getClass().getAnnotation(PluginInfo.class).name(); } + public static String formatTextAsIdentifier(String text) { + return text.toLowerCase().replaceAll("\\s", ""); + } + @Override public ValueBuilder methodName(ExtensionMethod method) { this.providerName = method.getMethod().getName(); @@ -127,7 +131,7 @@ public class ExtValueBuilder implements ValueBuilder { private ProviderInformation getProviderInformation(boolean percentage, String providedCondition) { ProviderInformation.Builder builder = ProviderInformation.builder(pluginName) .setName(providerName != null ? providerName - : text.toLowerCase().replaceAll("\\s", "")) + : formatTextAsIdentifier(text)) .setText(text) .setDescription(description) .setPriority(priority) @@ -153,7 +157,7 @@ public class ExtValueBuilder implements ValueBuilder { private ProviderInformation getTableProviderInformation(Color tableColor) { return ProviderInformation.builder(pluginName) .setName(providerName != null ? providerName - : text.toLowerCase().replaceAll("\\s", "")) + : formatTextAsIdentifier(text)) .setPriority(0) .setCondition(conditional) .setTab(tabName) 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 4fbcccc84..9d4dc2ca3 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 @@ -236,6 +236,8 @@ public class DataValueGatherer { addValuesToBuilder(dataBuilder, extension.getMethods().get(ExtensionMethod.ParameterType.PLAYER_UUID), parameters); gatherPlayer(parameters, (ExtDataBuilder) dataBuilder); + + dbSystem.getDatabase().executeTransaction(new RemoveInvalidResultsTransaction(extension.getPluginName(), serverInfo.getServerUUID(), ((ExtDataBuilder) dataBuilder).getInvalidatedValues())); } public void updateValues() {