mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-10-06 10:27:42 +02:00
Gatherer methods for server providers
This commit is contained in:
parent
ed4dff350a
commit
db90410487
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
import com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider;
|
||||
@ -27,10 +28,12 @@ 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.providers.StoreBooleanProviderTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerBooleanResultTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StoreServerBooleanResultTransaction;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@ -62,15 +65,20 @@ class BooleanProviderValueGatherer {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
Conditions gatherBooleanData(UUID playerUUID, String playerName) {
|
||||
Conditions gatherBooleanDataOfPlayer(UUID playerUUID, String playerName) {
|
||||
Conditions conditions = new Conditions();
|
||||
|
||||
List<DataProvider<Boolean>> unsatisifiedProviders = new ArrayList<>(dataProviders.getPlayerMethodsByType(Boolean.class));
|
||||
Set<DataProvider<Boolean>> satisfied = new HashSet<>();
|
||||
Set<DataProvider<Boolean>> satisfied;
|
||||
|
||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||
// Same with Method result store transaction creation
|
||||
Function<MethodWrapper<Boolean>, Callable<Boolean>> methodCaller = method -> () -> method.callMethod(extension, playerUUID, playerName);
|
||||
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTrancationCreator = (method, result) -> new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
|
||||
|
||||
do {
|
||||
// Loop through all unsatisfied providers to see if more conditions are satisfied
|
||||
satisfied = attemptToSatisfyMoreConditionsAndStoreResults(playerUUID, playerName, conditions, unsatisifiedProviders);
|
||||
satisfied = attemptToSatisfyMoreConditionsAndStoreResults(methodCaller, storeTrancationCreator, conditions, unsatisifiedProviders);
|
||||
// Remove now satisfied Providers so that they are not called again
|
||||
unsatisifiedProviders.removeAll(satisfied);
|
||||
// If no new conditions could be satisfied, stop looping.
|
||||
@ -79,7 +87,33 @@ class BooleanProviderValueGatherer {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
private Set<DataProvider<Boolean>> attemptToSatisfyMoreConditionsAndStoreResults(UUID playerUUID, String playerName, Conditions conditions, List<DataProvider<Boolean>> unsatisifiedProviders) {
|
||||
Conditions gatherBooleanDataOfServer() {
|
||||
Conditions conditions = new Conditions();
|
||||
|
||||
List<DataProvider<Boolean>> unsatisifiedProviders = new ArrayList<>(dataProviders.getServerMethodsByType(Boolean.class));
|
||||
Set<DataProvider<Boolean>> satisfied;
|
||||
|
||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||
// Same with Method result store transaction creation
|
||||
Function<MethodWrapper<Boolean>, Callable<Boolean>> methodCaller = method -> () -> method.callMethod(extension);
|
||||
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTransactionCreator = (method, result) -> new StoreServerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), result);
|
||||
|
||||
do {
|
||||
// Loop through all unsatisfied providers to see if more conditions are satisfied
|
||||
satisfied = attemptToSatisfyMoreConditionsAndStoreResults(methodCaller, storeTransactionCreator, conditions, unsatisifiedProviders);
|
||||
// Remove now satisfied Providers so that they are not called again
|
||||
unsatisifiedProviders.removeAll(satisfied);
|
||||
// If no new conditions could be satisfied, stop looping.
|
||||
} while (!satisfied.isEmpty());
|
||||
|
||||
return conditions;
|
||||
}
|
||||
|
||||
private Set<DataProvider<Boolean>> attemptToSatisfyMoreConditionsAndStoreResults(
|
||||
Function<MethodWrapper<Boolean>, Callable<Boolean>> methodCaller,
|
||||
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTransactionCreator,
|
||||
Conditions conditions, List<DataProvider<Boolean>> unsatisifiedProviders
|
||||
) {
|
||||
Set<DataProvider<Boolean>> satisfied = new HashSet<>();
|
||||
for (DataProvider<Boolean> booleanProvider : unsatisifiedProviders) {
|
||||
ProviderInformation providerInformation = booleanProvider.getProviderInformation();
|
||||
@ -95,7 +129,7 @@ class BooleanProviderValueGatherer {
|
||||
|
||||
MethodWrapper<Boolean> method = booleanProvider.getMethod();
|
||||
Boolean result = getMethodResult(
|
||||
() -> method.callMethod(extension, playerUUID, playerName),
|
||||
methodCaller.apply(method),
|
||||
throwable -> pluginName + " has invalid implementation, method " + method.getMethodName() + " threw exception: " + throwable.toString()
|
||||
);
|
||||
if (result == null) {
|
||||
@ -117,7 +151,7 @@ class BooleanProviderValueGatherer {
|
||||
satisfied.add(booleanProvider); // Prevents further attempts to call this provider for this player.
|
||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||
database.executeTransaction(new StoreBooleanProviderTransaction(booleanProvider, providedCondition.orElse(null), hidden, serverUUID));
|
||||
database.executeTransaction(new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
database.executeTransaction(storeTransactionCreator.apply(method, result));
|
||||
}
|
||||
return satisfied;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
@ -28,11 +29,14 @@ import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIc
|
||||
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.StorePlayerPercentageResultTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StoreServerDoubleResultTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StoreServerPercentageResultTransaction;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@ -64,31 +68,59 @@ class DoubleAndPercentageProviderValueGatherer {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
void gatherDoubleData(UUID playerUUID, String playerName, Conditions conditions) {
|
||||
void gatherDoubleDataOfPlayer(UUID playerUUID, String playerName, Conditions conditions) {
|
||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||
// Same with Method result store transaction creation
|
||||
Function<MethodWrapper<Double>, Callable<Double>> methodCaller = method -> () -> method.callMethod(extension, playerUUID, playerName);
|
||||
BiFunction<MethodWrapper<Double>, Double, Transaction> percStoreTransactionCreator = (method, result) -> new StorePlayerPercentageResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
|
||||
BiFunction<MethodWrapper<Double>, Double, Transaction> doubleStoreTransactionCreator = (method, result) -> new StorePlayerDoubleResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
|
||||
|
||||
for (DataProvider<Double> doubleProvider : dataProviders.getPlayerMethodsByType(Double.class)) {
|
||||
ProviderInformation providerInformation = doubleProvider.getProviderInformation();
|
||||
Optional<String> condition = providerInformation.getCondition();
|
||||
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
||||
continue; // Condition not met
|
||||
}
|
||||
gatherDoubleDataOfProvider(methodCaller, percStoreTransactionCreator, doubleStoreTransactionCreator, conditions, doubleProvider);
|
||||
}
|
||||
}
|
||||
|
||||
MethodWrapper<Double> method = doubleProvider.getMethod();
|
||||
Double result = getMethodResult(
|
||||
() -> method.callMethod(extension, playerUUID, playerName),
|
||||
throwable -> pluginName + " has invalid implementation, method " + method.getMethodName() + " threw exception: " + throwable.toString()
|
||||
);
|
||||
if (result == null) {
|
||||
continue;
|
||||
}
|
||||
void gatherDoubleDataOfServer(Conditions conditions) {
|
||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||
// Same with Method result store transaction creation
|
||||
Function<MethodWrapper<Double>, Callable<Double>> methodCaller = method -> () -> method.callMethod(extension);
|
||||
BiFunction<MethodWrapper<Double>, Double, Transaction> percStoreTransactionCreator = (method, result) -> new StoreServerPercentageResultTransaction(pluginName, serverUUID, method.getMethodName(), result);
|
||||
BiFunction<MethodWrapper<Double>, Double, Transaction> doubleStoreTransactionCreator = (method, result) -> new StoreServerDoubleResultTransaction(pluginName, serverUUID, method.getMethodName(), result);
|
||||
|
||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||
database.executeTransaction(new StoreDoubleProviderTransaction(doubleProvider, serverUUID));
|
||||
for (DataProvider<Double> doubleProvider : dataProviders.getServerMethodsByType(Double.class)) {
|
||||
gatherDoubleDataOfProvider(methodCaller, percStoreTransactionCreator, doubleStoreTransactionCreator, conditions, doubleProvider);
|
||||
}
|
||||
}
|
||||
|
||||
if (doubleProvider instanceof PercentageDataProvider) {
|
||||
database.executeTransaction(new StorePlayerPercentageResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
} else {
|
||||
database.executeTransaction(new StorePlayerDoubleResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
}
|
||||
private void gatherDoubleDataOfProvider(
|
||||
Function<MethodWrapper<Double>, Callable<Double>> methodCaller,
|
||||
BiFunction<MethodWrapper<Double>, Double, Transaction> percStoreTransactionCreator,
|
||||
BiFunction<MethodWrapper<Double>, Double, Transaction> doubleStoreTransactionCreator,
|
||||
Conditions conditions, DataProvider<Double> doubleProvider
|
||||
|
||||
) {
|
||||
ProviderInformation providerInformation = doubleProvider.getProviderInformation();
|
||||
Optional<String> condition = providerInformation.getCondition();
|
||||
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
||||
return;
|
||||
}
|
||||
|
||||
MethodWrapper<Double> method = doubleProvider.getMethod();
|
||||
Double result = getMethodResult(
|
||||
methodCaller.apply(method),
|
||||
throwable -> pluginName + " has invalid implementation, method " + method.getMethodName() + " threw exception: " + throwable.toString()
|
||||
);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||
database.executeTransaction(new StoreDoubleProviderTransaction(doubleProvider, serverUUID));
|
||||
|
||||
if (doubleProvider instanceof PercentageDataProvider) {
|
||||
database.executeTransaction(percStoreTransactionCreator.apply(method, result));
|
||||
} else {
|
||||
database.executeTransaction(doubleStoreTransactionCreator.apply(method, result));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.FormatType;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
@ -28,11 +29,13 @@ 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.providers.StoreNumberProviderTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerNumberResultTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StoreServerNumberResultTransaction;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@ -64,31 +67,55 @@ class NumberProviderValueGatherer {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
void gatherNumberData(UUID playerUUID, String playerName, Conditions conditions) {
|
||||
void gatherNumberDataOfPlayer(UUID playerUUID, String playerName, Conditions conditions) {
|
||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||
// Same with Method result store transaction creation
|
||||
Function<MethodWrapper<Long>, Callable<Long>> methodCaller = method -> () -> method.callMethod(extension, playerUUID, playerName);
|
||||
BiFunction<MethodWrapper<Long>, Long, Transaction> storeTransactionCreator = (method, result) -> new StorePlayerNumberResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
|
||||
|
||||
for (DataProvider<Long> numberProvider : dataProviders.getPlayerMethodsByType(Long.class)) {
|
||||
ProviderInformation providerInformation = numberProvider.getProviderInformation();
|
||||
Optional<String> condition = providerInformation.getCondition();
|
||||
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
||||
continue; // Condition not met
|
||||
}
|
||||
|
||||
MethodWrapper<Long> method = numberProvider.getMethod();
|
||||
Long result = getMethodResult(
|
||||
() -> method.callMethod(extension, playerUUID, playerName),
|
||||
throwable -> pluginName + " has invalid implementation, method " + method.getMethodName() + " threw exception: " + throwable.toString()
|
||||
);
|
||||
if (result == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FormatType formatType = NumberDataProvider.getFormatType(numberProvider);
|
||||
|
||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||
database.executeTransaction(new StoreNumberProviderTransaction(numberProvider, formatType, serverUUID));
|
||||
database.executeTransaction(new StorePlayerNumberResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
gatherNumberDataOfProvider(methodCaller, storeTransactionCreator, conditions, numberProvider);
|
||||
}
|
||||
}
|
||||
|
||||
void gatherNumberDataOfServer(Conditions conditions) {
|
||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||
// Same with Method result store transaction creation
|
||||
Function<MethodWrapper<Long>, Callable<Long>> methodCaller = method -> () -> method.callMethod(extension);
|
||||
BiFunction<MethodWrapper<Long>, Long, Transaction> storeTransactionCreator = (method, result) -> new StoreServerNumberResultTransaction(pluginName, serverUUID, method.getMethodName(), result);
|
||||
|
||||
for (DataProvider<Long> numberProvider : dataProviders.getServerMethodsByType(Long.class)) {
|
||||
gatherNumberDataOfProvider(methodCaller, storeTransactionCreator, conditions, numberProvider);
|
||||
}
|
||||
}
|
||||
|
||||
private void gatherNumberDataOfProvider(
|
||||
Function<MethodWrapper<Long>, Callable<Long>> methodCaller,
|
||||
BiFunction<MethodWrapper<Long>, Long, Transaction> storeTransactionCreator,
|
||||
Conditions conditions, DataProvider<Long> numberProvider
|
||||
) {
|
||||
ProviderInformation providerInformation = numberProvider.getProviderInformation();
|
||||
Optional<String> condition = providerInformation.getCondition();
|
||||
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
||||
return;
|
||||
}
|
||||
|
||||
MethodWrapper<Long> method = numberProvider.getMethod();
|
||||
Long result = getMethodResult(
|
||||
methodCaller.apply(method),
|
||||
throwable -> pluginName + " has invalid implementation, method " + method.getMethodName() + " threw exception: " + throwable.toString()
|
||||
);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
FormatType formatType = NumberDataProvider.getFormatType(numberProvider);
|
||||
|
||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||
database.executeTransaction(new StoreNumberProviderTransaction(numberProvider, formatType, serverUUID));
|
||||
database.executeTransaction(storeTransactionCreator.apply(method, result));
|
||||
}
|
||||
|
||||
private <T> T getMethodResult(Callable<T> callable, Function<Throwable, String> errorMsg) {
|
||||
try {
|
||||
return callable.call();
|
||||
@ -97,5 +124,4 @@ class NumberProviderValueGatherer {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -44,6 +44,10 @@ public class ProviderValueGatherer {
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final PluginLogger logger;
|
||||
private BooleanProviderValueGatherer booleanGatherer;
|
||||
private NumberProviderValueGatherer numberGatherer;
|
||||
private DoubleAndPercentageProviderValueGatherer doubleAndPercentageGatherer;
|
||||
private StringProviderValueGatherer stringGatherer;
|
||||
|
||||
public ProviderValueGatherer(
|
||||
DataExtension extension,
|
||||
@ -57,6 +61,27 @@ public class ProviderValueGatherer {
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.logger = logger;
|
||||
|
||||
booleanGatherer = new BooleanProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
);
|
||||
numberGatherer = new NumberProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
);
|
||||
doubleAndPercentageGatherer = new DoubleAndPercentageProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
);
|
||||
stringGatherer = new StringProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
);
|
||||
}
|
||||
|
||||
public void storeExtensionInformation() {
|
||||
@ -78,33 +103,16 @@ public class ProviderValueGatherer {
|
||||
}
|
||||
|
||||
public void updateValues(UUID playerUUID, String playerName) {
|
||||
Conditions conditions = gatherBooleanData(playerUUID, playerName);
|
||||
gatherValueData(playerUUID, playerName, conditions);
|
||||
Conditions conditions = booleanGatherer.gatherBooleanDataOfPlayer(playerUUID, playerName);
|
||||
numberGatherer.gatherNumberDataOfPlayer(playerUUID, playerName, conditions);
|
||||
doubleAndPercentageGatherer.gatherDoubleDataOfPlayer(playerUUID, playerName, conditions);
|
||||
stringGatherer.gatherStringDataOfPlayer(playerUUID, playerName, conditions);
|
||||
}
|
||||
|
||||
private Conditions gatherBooleanData(UUID playerUUID, String playerName) {
|
||||
return new BooleanProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
).gatherBooleanData(playerUUID, playerName);
|
||||
}
|
||||
|
||||
private void gatherValueData(UUID playerUUID, String playerName, Conditions conditions) {
|
||||
new NumberProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
).gatherNumberData(playerUUID, playerName, conditions);
|
||||
new DoubleAndPercentageProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
).gatherDoubleData(playerUUID, playerName, conditions);
|
||||
new StringProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
).gatherStringData(playerUUID, playerName, conditions);
|
||||
public void updateValues() {
|
||||
Conditions conditions = booleanGatherer.gatherBooleanDataOfServer();
|
||||
numberGatherer.gatherNumberDataOfServer(conditions);
|
||||
doubleAndPercentageGatherer.gatherDoubleDataOfServer(conditions);
|
||||
stringGatherer.gatherStringDataOfServer(conditions);
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
@ -27,12 +28,14 @@ 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.providers.StoreStringProviderTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerStringResultTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StoreServerStringResultTransaction;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@ -64,31 +67,56 @@ class StringProviderValueGatherer {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
void gatherStringData(UUID playerUUID, String playerName, Conditions conditions) {
|
||||
void gatherStringDataOfPlayer(UUID playerUUID, String playerName, Conditions conditions) {
|
||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||
// Same with Method result store transaction creation
|
||||
Function<MethodWrapper<String>, Callable<String>> methodCaller = method -> () -> method.callMethod(extension, playerUUID, playerName);
|
||||
BiFunction<MethodWrapper<String>, String, Transaction> storeTransactionCreator = (method, result) -> new StorePlayerStringResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
|
||||
|
||||
for (DataProvider<String> stringProvider : dataProviders.getPlayerMethodsByType(String.class)) {
|
||||
ProviderInformation providerInformation = stringProvider.getProviderInformation();
|
||||
Optional<String> condition = providerInformation.getCondition();
|
||||
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
||||
continue; // Condition not met
|
||||
}
|
||||
|
||||
MethodWrapper<String> method = stringProvider.getMethod();
|
||||
String result = getMethodResult(
|
||||
() -> method.callMethod(extension, playerUUID, playerName),
|
||||
throwable -> pluginName + " has invalid implementation, method " + method.getMethodName() + " threw exception: " + throwable.toString()
|
||||
);
|
||||
if (result == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result = StringUtils.truncate(result, 50);
|
||||
|
||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||
database.executeTransaction(new StoreStringProviderTransaction(stringProvider, StringDataProvider.isPlayerName(stringProvider), serverUUID));
|
||||
database.executeTransaction(new StorePlayerStringResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
gatherStringDataOfProvider(methodCaller, storeTransactionCreator, conditions, stringProvider);
|
||||
}
|
||||
}
|
||||
|
||||
void gatherStringDataOfServer(Conditions conditions) {
|
||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||
// Same with Method result store transaction creation
|
||||
Function<MethodWrapper<String>, Callable<String>> methodCaller = method -> () -> method.callMethod(extension);
|
||||
BiFunction<MethodWrapper<String>, String, Transaction> storeTransactionCreator = (method, result) -> new StoreServerStringResultTransaction(pluginName, serverUUID, method.getMethodName(), result);
|
||||
|
||||
for (DataProvider<String> stringProvider : dataProviders.getServerMethodsByType(String.class)) {
|
||||
gatherStringDataOfProvider(methodCaller, storeTransactionCreator, conditions, stringProvider);
|
||||
}
|
||||
}
|
||||
|
||||
private void gatherStringDataOfProvider(
|
||||
Function<MethodWrapper<String>, Callable<String>> methodCaller,
|
||||
BiFunction<MethodWrapper<String>, String, Transaction> storeTransactionCreator,
|
||||
Conditions conditions,
|
||||
DataProvider<String> stringProvider
|
||||
) {
|
||||
ProviderInformation providerInformation = stringProvider.getProviderInformation();
|
||||
Optional<String> condition = providerInformation.getCondition();
|
||||
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
||||
return;
|
||||
}
|
||||
|
||||
MethodWrapper<String> method = stringProvider.getMethod();
|
||||
String result = getMethodResult(
|
||||
methodCaller.apply(method),
|
||||
throwable -> pluginName + " has invalid implementation, method " + method.getMethodName() + " threw exception: " + throwable.toString()
|
||||
);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = StringUtils.truncate(result, 50);
|
||||
|
||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||
database.executeTransaction(new StoreStringProviderTransaction(stringProvider, StringDataProvider.isPlayerName(stringProvider), serverUUID));
|
||||
database.executeTransaction(storeTransactionCreator.apply(method, result));
|
||||
}
|
||||
|
||||
private <T> T getMethodResult(Callable<T> callable, Function<Throwable, String> errorMsg) {
|
||||
try {
|
||||
return callable.call();
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.storage.transactions.results;
|
||||
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class StoreServerBooleanResultTransaction extends Transaction {
|
||||
|
||||
private final String pluginName;
|
||||
private final UUID serverUUID;
|
||||
private final String providerName;
|
||||
|
||||
private final boolean result;
|
||||
|
||||
public StoreServerBooleanResultTransaction(String pluginName, UUID serverUUID, String providerName, boolean result) {
|
||||
this.pluginName = pluginName;
|
||||
this.serverUUID = serverUUID;
|
||||
this.providerName = providerName;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
// TODO
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.storage.transactions.results;
|
||||
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.DoubleDataProvider}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class StoreServerDoubleResultTransaction extends Transaction {
|
||||
|
||||
private final String pluginName;
|
||||
private final UUID serverUUID;
|
||||
private final String providerName;
|
||||
|
||||
private final double result;
|
||||
|
||||
public StoreServerDoubleResultTransaction(String pluginName, UUID serverUUID, String providerName, double result) {
|
||||
this.pluginName = pluginName;
|
||||
this.serverUUID = serverUUID;
|
||||
this.providerName = providerName;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
// TODO
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.storage.transactions.results;
|
||||
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.NumberDataProvider}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class StoreServerNumberResultTransaction extends Transaction {
|
||||
|
||||
private final String pluginName;
|
||||
private final UUID serverUUID;
|
||||
private final String providerName;
|
||||
|
||||
private final long result;
|
||||
|
||||
public StoreServerNumberResultTransaction(String pluginName, UUID serverUUID, String providerName, long result) {
|
||||
this.pluginName = pluginName;
|
||||
this.serverUUID = serverUUID;
|
||||
this.providerName = providerName;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
// TODO
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.storage.transactions.results;
|
||||
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class StoreServerPercentageResultTransaction extends Transaction {
|
||||
|
||||
private final String pluginName;
|
||||
private final UUID serverUUID;
|
||||
private final String providerName;
|
||||
|
||||
private final double result;
|
||||
|
||||
public StoreServerPercentageResultTransaction(String pluginName, UUID serverUUID, String providerName, double result) {
|
||||
this.pluginName = pluginName;
|
||||
this.serverUUID = serverUUID;
|
||||
this.providerName = providerName;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
// TODO
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.storage.transactions.results;
|
||||
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class StoreServerStringResultTransaction extends Transaction {
|
||||
|
||||
private final String pluginName;
|
||||
private final UUID serverUUID;
|
||||
private final String providerName;
|
||||
|
||||
private final String result;
|
||||
|
||||
public StoreServerStringResultTransaction(String pluginName, UUID serverUUID, String providerName, String result) {
|
||||
this.pluginName = pluginName;
|
||||
this.serverUUID = serverUUID;
|
||||
this.providerName = providerName;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
// TODO
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user