mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-04 19:01:16 +02:00
Added flow for Negated conditions
Negated conditions' names are prefixed with not_ This allows checking against negated Conditionals and does not need adding more table rows.
This commit is contained in:
parent
91bb5bf31b
commit
c77ec3fd79
|
@ -67,7 +67,7 @@ public class ExtensionProviderTable {
|
||||||
.column(DESCRIPTION, Sql.varchar(150))
|
.column(DESCRIPTION, Sql.varchar(150))
|
||||||
.column(PRIORITY, INT).notNull().defaultValue("0")
|
.column(PRIORITY, INT).notNull().defaultValue("0")
|
||||||
.column(GROUPABLE, BOOL).notNull().defaultValue(false)
|
.column(GROUPABLE, BOOL).notNull().defaultValue(false)
|
||||||
.column(CONDITION, Sql.varchar(50))
|
.column(CONDITION, Sql.varchar(54)) // 50 + 4 for "not_"
|
||||||
.column(PROVIDED_CONDITION, Sql.varchar(50))
|
.column(PROVIDED_CONDITION, Sql.varchar(50))
|
||||||
.column(FORMAT_TYPE, Sql.varchar(25))
|
.column(FORMAT_TYPE, Sql.varchar(25))
|
||||||
.column(IS_PLAYER_NAME, BOOL).notNull().defaultValue(false)
|
.column(IS_PLAYER_NAME, BOOL).notNull().defaultValue(false)
|
||||||
|
|
|
@ -138,7 +138,7 @@ public class DataProviderExtractor {
|
||||||
|
|
||||||
factory.placeToDataProviders(
|
factory.placeToDataProviders(
|
||||||
dataProviders, method, annotation,
|
dataProviders, method, annotation,
|
||||||
conditional.map(Conditional::value).orElse(null),
|
conditional.orElse(null),
|
||||||
tab.map(Tab::value).orElse(null),
|
tab.map(Tab::value).orElse(null),
|
||||||
pluginInfo.name()
|
pluginInfo.name()
|
||||||
);
|
);
|
||||||
|
@ -157,7 +157,7 @@ public class DataProviderExtractor {
|
||||||
interface DataProviderFactory<T extends Annotation> {
|
interface DataProviderFactory<T extends Annotation> {
|
||||||
void placeToDataProviders(
|
void placeToDataProviders(
|
||||||
DataProviders dataProviders,
|
DataProviders dataProviders,
|
||||||
Method method, T annotation, String condition, String tab, String pluginName
|
Method method, T annotation, Conditional condition, String tab, String pluginName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.extension.implementation;
|
package com.djrapitops.plan.extension.implementation;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.annotation.Conditional;
|
||||||
import com.djrapitops.plan.extension.icon.Icon;
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
import com.djrapitops.plan.extension.implementation.results.player.ExtensionDescriptive;
|
import com.djrapitops.plan.extension.implementation.results.player.ExtensionDescriptive;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -31,10 +32,10 @@ public class ProviderInformation extends ExtensionDescriptive {
|
||||||
|
|
||||||
private final String pluginName;
|
private final String pluginName;
|
||||||
private final String tab; // can be null
|
private final String tab; // can be null
|
||||||
private final String condition; // can be null
|
private final Conditional condition; // can be null
|
||||||
|
|
||||||
public ProviderInformation(
|
public ProviderInformation(
|
||||||
String pluginName, String name, String text, String description, Icon icon, int priority, String tab, String condition
|
String pluginName, String name, String text, String description, Icon icon, int priority, String tab, Conditional condition
|
||||||
) {
|
) {
|
||||||
super(name, text, description, icon, priority);
|
super(name, text, description, icon, priority);
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
|
@ -51,6 +52,6 @@ public class ProviderInformation extends ExtensionDescriptive {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<String> getCondition() {
|
public Optional<String> getCondition() {
|
||||||
return condition == null || condition.isEmpty() ? Optional.empty() : Optional.of(StringUtils.truncate(condition, 50));
|
return condition == null || condition.value().isEmpty() ? Optional.empty() : Optional.of((condition.negated() ? "not_" : "") + StringUtils.truncate(condition.value(), 50));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,6 +17,7 @@
|
||||||
package com.djrapitops.plan.extension.implementation.providers;
|
package com.djrapitops.plan.extension.implementation.providers;
|
||||||
|
|
||||||
import com.djrapitops.plan.extension.annotation.BooleanProvider;
|
import com.djrapitops.plan.extension.annotation.BooleanProvider;
|
||||||
|
import com.djrapitops.plan.extension.annotation.Conditional;
|
||||||
import com.djrapitops.plan.extension.icon.Icon;
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -43,7 +44,7 @@ public class BooleanDataProvider extends DataProvider<Boolean> {
|
||||||
|
|
||||||
public static void placeToDataProviders(
|
public static void placeToDataProviders(
|
||||||
DataProviders dataProviders, Method method, BooleanProvider annotation,
|
DataProviders dataProviders, Method method, BooleanProvider annotation,
|
||||||
String condition, String tab, String pluginName
|
Conditional condition, String tab, String pluginName
|
||||||
) {
|
) {
|
||||||
MethodWrapper<Boolean> methodWrapper = new MethodWrapper<>(method, Boolean.class);
|
MethodWrapper<Boolean> methodWrapper = new MethodWrapper<>(method, Boolean.class);
|
||||||
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
|
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.extension.implementation.providers;
|
package com.djrapitops.plan.extension.implementation.providers;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.annotation.Conditional;
|
||||||
import com.djrapitops.plan.extension.annotation.DoubleProvider;
|
import com.djrapitops.plan.extension.annotation.DoubleProvider;
|
||||||
import com.djrapitops.plan.extension.icon.Icon;
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||||
|
@ -37,7 +38,7 @@ public class DoubleDataProvider extends DataProvider<Double> {
|
||||||
|
|
||||||
public static void placeToDataProviders(
|
public static void placeToDataProviders(
|
||||||
DataProviders dataProviders, Method method, DoubleProvider annotation,
|
DataProviders dataProviders, Method method, DoubleProvider annotation,
|
||||||
String condition, String tab, String pluginName
|
Conditional condition, String tab, String pluginName
|
||||||
) {
|
) {
|
||||||
MethodWrapper<Double> methodWrapper = new MethodWrapper<>(method, Double.class);
|
MethodWrapper<Double> methodWrapper = new MethodWrapper<>(method, Double.class);
|
||||||
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
|
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package com.djrapitops.plan.extension.implementation.providers;
|
package com.djrapitops.plan.extension.implementation.providers;
|
||||||
|
|
||||||
import com.djrapitops.plan.extension.FormatType;
|
import com.djrapitops.plan.extension.FormatType;
|
||||||
|
import com.djrapitops.plan.extension.annotation.Conditional;
|
||||||
import com.djrapitops.plan.extension.annotation.NumberProvider;
|
import com.djrapitops.plan.extension.annotation.NumberProvider;
|
||||||
import com.djrapitops.plan.extension.icon.Icon;
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||||
|
@ -41,7 +42,7 @@ public class NumberDataProvider extends DataProvider<Long> {
|
||||||
|
|
||||||
public static void placeToDataProviders(
|
public static void placeToDataProviders(
|
||||||
DataProviders dataProviders, Method method, NumberProvider annotation,
|
DataProviders dataProviders, Method method, NumberProvider annotation,
|
||||||
String condition, String tab, String pluginName
|
Conditional condition, String tab, String pluginName
|
||||||
) {
|
) {
|
||||||
MethodWrapper<Long> methodWrapper = new MethodWrapper<>(method, Long.class);
|
MethodWrapper<Long> methodWrapper = new MethodWrapper<>(method, Long.class);
|
||||||
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
|
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.extension.implementation.providers;
|
package com.djrapitops.plan.extension.implementation.providers;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.annotation.Conditional;
|
||||||
import com.djrapitops.plan.extension.annotation.PercentageProvider;
|
import com.djrapitops.plan.extension.annotation.PercentageProvider;
|
||||||
import com.djrapitops.plan.extension.icon.Icon;
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||||
|
@ -37,7 +38,7 @@ public class PercentageDataProvider extends DataProvider<Double> {
|
||||||
|
|
||||||
public static void placeToDataProviders(
|
public static void placeToDataProviders(
|
||||||
DataProviders dataProviders, Method method, PercentageProvider annotation,
|
DataProviders dataProviders, Method method, PercentageProvider annotation,
|
||||||
String condition, String tab, String pluginName
|
Conditional condition, String tab, String pluginName
|
||||||
) {
|
) {
|
||||||
MethodWrapper<Double> methodWrapper = new MethodWrapper<>(method, Double.class);
|
MethodWrapper<Double> methodWrapper = new MethodWrapper<>(method, Double.class);
|
||||||
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
|
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.extension.implementation.providers;
|
package com.djrapitops.plan.extension.implementation.providers;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.annotation.Conditional;
|
||||||
import com.djrapitops.plan.extension.annotation.StringProvider;
|
import com.djrapitops.plan.extension.annotation.StringProvider;
|
||||||
import com.djrapitops.plan.extension.icon.Icon;
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||||
|
@ -40,7 +41,7 @@ public class StringDataProvider extends DataProvider<String> {
|
||||||
|
|
||||||
public static void placeToDataProviders(
|
public static void placeToDataProviders(
|
||||||
DataProviders dataProviders, Method method, StringProvider annotation,
|
DataProviders dataProviders, Method method, StringProvider annotation,
|
||||||
String condition, String tab, String pluginName
|
Conditional condition, String tab, String pluginName
|
||||||
) {
|
) {
|
||||||
MethodWrapper<String> methodWrapper = new MethodWrapper<>(method, String.class);
|
MethodWrapper<String> methodWrapper = new MethodWrapper<>(method, String.class);
|
||||||
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
|
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
|
||||||
|
|
|
@ -18,10 +18,12 @@ package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||||
|
|
||||||
import com.djrapitops.plan.db.Database;
|
import com.djrapitops.plan.db.Database;
|
||||||
import com.djrapitops.plan.extension.DataExtension;
|
import com.djrapitops.plan.extension.DataExtension;
|
||||||
|
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
||||||
|
import com.djrapitops.plan.extension.implementation.results.player.Conditions;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreBooleanProviderTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreBooleanProviderTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerBooleanResultTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerBooleanResultTransaction;
|
||||||
|
@ -60,8 +62,8 @@ class BooleanProviderValueGatherer {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> gatherBooleanData(UUID playerUUID, String playerName) {
|
Conditions gatherBooleanData(UUID playerUUID, String playerName) {
|
||||||
Set<String> providedConditions = new HashSet<>();
|
Conditions conditions = new Conditions();
|
||||||
|
|
||||||
List<DataProvider<Boolean>> unsatisifiedProviders = new ArrayList<>(dataProviders.getPlayerMethodsByType(Boolean.class));
|
List<DataProvider<Boolean>> unsatisifiedProviders = new ArrayList<>(dataProviders.getPlayerMethodsByType(Boolean.class));
|
||||||
Set<DataProvider<Boolean>> satisfied = new HashSet<>();
|
Set<DataProvider<Boolean>> satisfied = new HashSet<>();
|
||||||
|
@ -71,9 +73,11 @@ class BooleanProviderValueGatherer {
|
||||||
satisfied.clear();
|
satisfied.clear();
|
||||||
// Loop through all unsatisfied providers to see if more conditions are satisfied
|
// Loop through all unsatisfied providers to see if more conditions are satisfied
|
||||||
for (DataProvider<Boolean> booleanProvider : unsatisifiedProviders) {
|
for (DataProvider<Boolean> booleanProvider : unsatisifiedProviders) {
|
||||||
Optional<String> condition = booleanProvider.getProviderInformation().getCondition();
|
ProviderInformation providerInformation = booleanProvider.getProviderInformation();
|
||||||
if (condition.isPresent() && !providedConditions.contains(condition.get())) {
|
|
||||||
continue; // Condition not met
|
Optional<String> condition = providerInformation.getCondition();
|
||||||
|
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<String> providedCondition = BooleanDataProvider.getProvidedCondition(booleanProvider);
|
Optional<String> providedCondition = BooleanDataProvider.getProvidedCondition(booleanProvider);
|
||||||
|
@ -88,12 +92,18 @@ class BooleanProviderValueGatherer {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result && providedCondition.isPresent()) {
|
if (providedCondition.isPresent()) {
|
||||||
providedConditions.add(providedCondition.get()); // The condition was fulfilled for this player.
|
if (result) {
|
||||||
|
// The condition was fulfilled (true) for this player.
|
||||||
|
conditions.conditionFulfilled(providedCondition.get());
|
||||||
|
} else {
|
||||||
|
// The negated condition was fulfilled (false) for this player.
|
||||||
|
conditions.conditionFulfilled("not_" + providedCondition.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
satisfied.add(booleanProvider); // Prevents further attempts to call this provider for this player.
|
satisfied.add(booleanProvider); // Prevents further attempts to call this provider for this player.
|
||||||
database.executeTransaction(new StoreIconTransaction(booleanProvider.getProviderInformation().getIcon()));
|
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||||
database.executeTransaction(new StoreBooleanProviderTransaction(booleanProvider, providedCondition.orElse(null), serverUUID));
|
database.executeTransaction(new StoreBooleanProviderTransaction(booleanProvider, providedCondition.orElse(null), serverUUID));
|
||||||
database.executeTransaction(new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
database.executeTransaction(new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||||
}
|
}
|
||||||
|
@ -102,7 +112,7 @@ class BooleanProviderValueGatherer {
|
||||||
// If no new conditions could be satisfied, stop looping.
|
// If no new conditions could be satisfied, stop looping.
|
||||||
} while (!satisfied.isEmpty());
|
} while (!satisfied.isEmpty());
|
||||||
|
|
||||||
return providedConditions;
|
return conditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> T getMethodResult(Callable<T> callable, Function<Throwable, String> errorMsg) {
|
private <T> T getMethodResult(Callable<T> callable, Function<Throwable, String> errorMsg) {
|
||||||
|
|
|
@ -18,10 +18,12 @@ package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||||
|
|
||||||
import com.djrapitops.plan.db.Database;
|
import com.djrapitops.plan.db.Database;
|
||||||
import com.djrapitops.plan.extension.DataExtension;
|
import com.djrapitops.plan.extension.DataExtension;
|
||||||
|
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider;
|
||||||
|
import com.djrapitops.plan.extension.implementation.results.player.Conditions;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreDoubleProviderTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreDoubleProviderTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerDoubleResultTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerDoubleResultTransaction;
|
||||||
|
@ -29,7 +31,6 @@ import com.djrapitops.plan.extension.implementation.storage.transactions.results
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -63,10 +64,11 @@ class DoubleAndPercentageProviderValueGatherer {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gatherDoubleData(UUID playerUUID, String playerName, Set<String> providedConditions) {
|
void gatherDoubleData(UUID playerUUID, String playerName, Conditions conditions) {
|
||||||
for (DataProvider<Double> doubleProvider : dataProviders.getPlayerMethodsByType(Double.class)) {
|
for (DataProvider<Double> doubleProvider : dataProviders.getPlayerMethodsByType(Double.class)) {
|
||||||
Optional<String> condition = doubleProvider.getProviderInformation().getCondition();
|
ProviderInformation providerInformation = doubleProvider.getProviderInformation();
|
||||||
if (condition.isPresent() && !providedConditions.contains(condition.get())) {
|
Optional<String> condition = providerInformation.getCondition();
|
||||||
|
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
||||||
continue; // Condition not met
|
continue; // Condition not met
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +81,7 @@ class DoubleAndPercentageProviderValueGatherer {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
database.executeTransaction(new StoreIconTransaction(doubleProvider.getProviderInformation().getIcon()));
|
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||||
database.executeTransaction(new StoreDoubleProviderTransaction(doubleProvider, serverUUID));
|
database.executeTransaction(new StoreDoubleProviderTransaction(doubleProvider, serverUUID));
|
||||||
|
|
||||||
if (doubleProvider instanceof PercentageDataProvider) {
|
if (doubleProvider instanceof PercentageDataProvider) {
|
||||||
|
|
|
@ -19,17 +19,18 @@ package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||||
import com.djrapitops.plan.db.Database;
|
import com.djrapitops.plan.db.Database;
|
||||||
import com.djrapitops.plan.extension.DataExtension;
|
import com.djrapitops.plan.extension.DataExtension;
|
||||||
import com.djrapitops.plan.extension.FormatType;
|
import com.djrapitops.plan.extension.FormatType;
|
||||||
|
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.NumberDataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.NumberDataProvider;
|
||||||
|
import com.djrapitops.plan.extension.implementation.results.player.Conditions;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreNumberProviderTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreNumberProviderTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerNumberResultTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerNumberResultTransaction;
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -63,10 +64,11 @@ class NumberProviderValueGatherer {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gatherNumberData(UUID playerUUID, String playerName, Set<String> providedConditions) {
|
void gatherNumberData(UUID playerUUID, String playerName, Conditions conditions) {
|
||||||
for (DataProvider<Long> numberProvider : dataProviders.getPlayerMethodsByType(Long.class)) {
|
for (DataProvider<Long> numberProvider : dataProviders.getPlayerMethodsByType(Long.class)) {
|
||||||
Optional<String> condition = numberProvider.getProviderInformation().getCondition();
|
ProviderInformation providerInformation = numberProvider.getProviderInformation();
|
||||||
if (condition.isPresent() && !providedConditions.contains(condition.get())) {
|
Optional<String> condition = providerInformation.getCondition();
|
||||||
|
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
||||||
continue; // Condition not met
|
continue; // Condition not met
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +83,7 @@ class NumberProviderValueGatherer {
|
||||||
|
|
||||||
FormatType formatType = NumberDataProvider.getFormatType(numberProvider);
|
FormatType formatType = NumberDataProvider.getFormatType(numberProvider);
|
||||||
|
|
||||||
database.executeTransaction(new StoreIconTransaction(numberProvider.getProviderInformation().getIcon()));
|
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||||
database.executeTransaction(new StoreNumberProviderTransaction(numberProvider, formatType, serverUUID));
|
database.executeTransaction(new StoreNumberProviderTransaction(numberProvider, formatType, serverUUID));
|
||||||
database.executeTransaction(new StorePlayerNumberResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
database.executeTransaction(new StorePlayerNumberResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import com.djrapitops.plan.extension.DataExtension;
|
||||||
import com.djrapitops.plan.extension.icon.Icon;
|
import com.djrapitops.plan.extension.icon.Icon;
|
||||||
import com.djrapitops.plan.extension.implementation.DataProviderExtractor;
|
import com.djrapitops.plan.extension.implementation.DataProviderExtractor;
|
||||||
import com.djrapitops.plan.extension.implementation.TabInformation;
|
import com.djrapitops.plan.extension.implementation.TabInformation;
|
||||||
|
import com.djrapitops.plan.extension.implementation.results.player.Conditions;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StorePluginTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.StorePluginTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreTabInformationTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreTabInformationTransaction;
|
||||||
|
@ -29,7 +30,6 @@ import com.djrapitops.plan.system.database.DBSystem;
|
||||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,11 +79,11 @@ public class ProviderValueGatherer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateValues(UUID playerUUID, String playerName) {
|
public void updateValues(UUID playerUUID, String playerName) {
|
||||||
Set<String> providedConditions = gatherBooleanData(playerUUID, playerName);
|
Conditions conditions = gatherBooleanData(playerUUID, playerName);
|
||||||
gatherValueData(playerUUID, playerName, providedConditions);
|
gatherValueData(playerUUID, playerName, conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> gatherBooleanData(UUID playerUUID, String playerName) {
|
private Conditions gatherBooleanData(UUID playerUUID, String playerName) {
|
||||||
return new BooleanProviderValueGatherer(
|
return new BooleanProviderValueGatherer(
|
||||||
extractor.getPluginName(), extension,
|
extractor.getPluginName(), extension,
|
||||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||||
|
@ -91,21 +91,21 @@ public class ProviderValueGatherer {
|
||||||
).gatherBooleanData(playerUUID, playerName);
|
).gatherBooleanData(playerUUID, playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void gatherValueData(UUID playerUUID, String playerName, Set<String> providedConditions) {
|
private void gatherValueData(UUID playerUUID, String playerName, Conditions conditions) {
|
||||||
new NumberProviderValueGatherer(
|
new NumberProviderValueGatherer(
|
||||||
extractor.getPluginName(), extension,
|
extractor.getPluginName(), extension,
|
||||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||||
extractor.getDataProviders(), logger
|
extractor.getDataProviders(), logger
|
||||||
).gatherNumberData(playerUUID, playerName, providedConditions);
|
).gatherNumberData(playerUUID, playerName, conditions);
|
||||||
new DoubleAndPercentageProviderValueGatherer(
|
new DoubleAndPercentageProviderValueGatherer(
|
||||||
extractor.getPluginName(), extension,
|
extractor.getPluginName(), extension,
|
||||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||||
extractor.getDataProviders(), logger
|
extractor.getDataProviders(), logger
|
||||||
).gatherDoubleData(playerUUID, playerName, providedConditions);
|
).gatherDoubleData(playerUUID, playerName, conditions);
|
||||||
new StringProviderValueGatherer(
|
new StringProviderValueGatherer(
|
||||||
extractor.getPluginName(), extension,
|
extractor.getPluginName(), extension,
|
||||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||||
extractor.getDataProviders(), logger
|
extractor.getDataProviders(), logger
|
||||||
).gatherStringData(playerUUID, playerName, providedConditions);
|
).gatherStringData(playerUUID, playerName, conditions);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,10 +18,12 @@ package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||||
|
|
||||||
import com.djrapitops.plan.db.Database;
|
import com.djrapitops.plan.db.Database;
|
||||||
import com.djrapitops.plan.extension.DataExtension;
|
import com.djrapitops.plan.extension.DataExtension;
|
||||||
|
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.StringDataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.StringDataProvider;
|
||||||
|
import com.djrapitops.plan.extension.implementation.results.player.Conditions;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreStringProviderTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreStringProviderTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerStringResultTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerStringResultTransaction;
|
||||||
|
@ -29,7 +31,6 @@ import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -63,10 +64,11 @@ class StringProviderValueGatherer {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gatherStringData(UUID playerUUID, String playerName, Set<String> providedConditions) {
|
void gatherStringData(UUID playerUUID, String playerName, Conditions conditions) {
|
||||||
for (DataProvider<String> stringProvider : dataProviders.getPlayerMethodsByType(String.class)) {
|
for (DataProvider<String> stringProvider : dataProviders.getPlayerMethodsByType(String.class)) {
|
||||||
Optional<String> condition = stringProvider.getProviderInformation().getCondition();
|
ProviderInformation providerInformation = stringProvider.getProviderInformation();
|
||||||
if (condition.isPresent() && !providedConditions.contains(condition.get())) {
|
Optional<String> condition = providerInformation.getCondition();
|
||||||
|
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
||||||
continue; // Condition not met
|
continue; // Condition not met
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +83,7 @@ class StringProviderValueGatherer {
|
||||||
|
|
||||||
result = StringUtils.truncate(result, 50);
|
result = StringUtils.truncate(result, 50);
|
||||||
|
|
||||||
database.executeTransaction(new StoreIconTransaction(stringProvider.getProviderInformation().getIcon()));
|
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||||
database.executeTransaction(new StoreStringProviderTransaction(stringProvider, StringDataProvider.isPlayerName(stringProvider), serverUUID));
|
database.executeTransaction(new StoreStringProviderTransaction(stringProvider, StringDataProvider.isPlayerName(stringProvider), serverUUID));
|
||||||
database.executeTransaction(new StorePlayerStringResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
database.executeTransaction(new StorePlayerStringResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.extension.implementation.results.player;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility object for managing conditions.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class Conditions {
|
||||||
|
|
||||||
|
private final Set<String> fulfilledConditions;
|
||||||
|
|
||||||
|
public Conditions() {
|
||||||
|
this.fulfilledConditions = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNotFulfilled(String condition) {
|
||||||
|
return !fulfilledConditions.contains(condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void conditionFulfilled(String condition) {
|
||||||
|
fulfilledConditions.add(condition);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user