mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-07 03:10:56 +01:00
Plan API 5.2-R0.6: InvalidateMethod equivalent to ExtensionDataBuilder
This commit is contained in:
parent
5cecde5500
commit
af858b8455
@ -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 {
|
||||
|
@ -72,6 +72,14 @@ public interface ExtensionDataBuilder {
|
||||
*/
|
||||
<T> ExtensionDataBuilder addValue(Class<T> ofType, Supplier<DataValue<T>> 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.
|
||||
*
|
||||
|
@ -28,12 +28,15 @@ import java.util.function.Supplier;
|
||||
|
||||
public class ExtDataBuilder implements ExtensionDataBuilder {
|
||||
|
||||
private final List<ClassValuePair> values;
|
||||
private final DataExtension extension;
|
||||
|
||||
private final List<ClassValuePair> values;
|
||||
private final Set<String> 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<ClassValuePair> getValues() {
|
||||
Collections.sort(values);
|
||||
return values;
|
||||
@ -80,6 +89,10 @@ public class ExtDataBuilder implements ExtensionDataBuilder {
|
||||
this.values.addAll(((ExtDataBuilder) builder).values);
|
||||
}
|
||||
|
||||
public Set<String> getInvalidatedValues() {
|
||||
return invalidatedValues;
|
||||
}
|
||||
|
||||
public static final class ClassValuePair implements Comparable<ClassValuePair> {
|
||||
private final Class<?> type;
|
||||
private final DataValue<?> value;
|
||||
|
@ -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)
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user