mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-29 23:17:28 +02:00
Player data gathering for all providers:
- Incremental condition resolution of BooleanProvider conditions - Gathering of Number and String values - Gathering and disambiguation between double and percentage providers.
This commit is contained in:
parent
f10c2352df
commit
590d5c0e64
@ -18,6 +18,8 @@ package com.djrapitops.plan.extension.implementation;
|
||||
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents the annotation information provided on a method.
|
||||
*
|
||||
@ -71,11 +73,11 @@ public class ProviderInformation {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public String getTab() {
|
||||
return tab;
|
||||
public Optional<String> getTab() {
|
||||
return Optional.ofNullable(tab);
|
||||
}
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
public Optional<String> getCondition() {
|
||||
return Optional.ofNullable(condition);
|
||||
}
|
||||
}
|
@ -54,6 +54,13 @@ public class BooleanDataProvider extends DataProvider<Boolean> {
|
||||
dataProviders.put(new BooleanDataProvider(providerInformation, methodWrapper, annotation.conditionName()));
|
||||
}
|
||||
|
||||
public static Optional<String> getProvidedCondition(DataProvider<Boolean> provider) {
|
||||
if (provider instanceof BooleanDataProvider) {
|
||||
return ((BooleanDataProvider) provider).getProvidedCondition();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<String> getProvidedCondition() {
|
||||
return Optional.ofNullable(providedCondition);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.extension.implementation.providers;
|
||||
|
||||
import com.djrapitops.plan.extension.FormatType;
|
||||
import com.djrapitops.plan.extension.annotation.NumberProvider;
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
@ -31,8 +32,11 @@ import java.lang.reflect.Method;
|
||||
*/
|
||||
public class NumberDataProvider extends DataProvider<Long> {
|
||||
|
||||
private NumberDataProvider(ProviderInformation providerInformation, MethodWrapper<Long> methodWrapper) {
|
||||
private final FormatType formatType;
|
||||
|
||||
private NumberDataProvider(ProviderInformation providerInformation, MethodWrapper<Long> methodWrapper, FormatType formatType) {
|
||||
super(providerInformation, methodWrapper);
|
||||
this.formatType = formatType;
|
||||
}
|
||||
|
||||
public static void placeToDataProviders(
|
||||
@ -46,6 +50,17 @@ public class NumberDataProvider extends DataProvider<Long> {
|
||||
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), tab, condition
|
||||
);
|
||||
|
||||
dataProviders.put(new NumberDataProvider(providerInformation, methodWrapper));
|
||||
dataProviders.put(new NumberDataProvider(providerInformation, methodWrapper, annotation.format()));
|
||||
}
|
||||
|
||||
public static FormatType getFormatType(DataProvider<Long> provider) {
|
||||
if (provider instanceof NumberDataProvider) {
|
||||
return ((NumberDataProvider) provider).getFormatType();
|
||||
}
|
||||
return FormatType.NONE;
|
||||
}
|
||||
|
||||
public FormatType getFormatType() {
|
||||
return formatType;
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreBooleanProviderTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerBooleanResultTransaction;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Gathers BooleanProvider method data.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
class BooleanProviderValueGatherer {
|
||||
|
||||
private final String pluginName;
|
||||
private final DataExtension extension;
|
||||
private final UUID serverUUID;
|
||||
|
||||
private final Database database;
|
||||
private final DataProviders dataProviders;
|
||||
private final PluginLogger logger;
|
||||
|
||||
BooleanProviderValueGatherer(
|
||||
String pluginName, DataExtension extension,
|
||||
UUID serverUUID, Database database,
|
||||
DataProviders dataProviders,
|
||||
PluginLogger logger
|
||||
) {
|
||||
this.pluginName = pluginName;
|
||||
this.extension = extension;
|
||||
this.serverUUID = serverUUID;
|
||||
this.database = database;
|
||||
this.dataProviders = dataProviders;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
Set<String> gatherBooleanData(UUID playerUUID, String playerName) {
|
||||
Set<String> providedConditions = new HashSet<>();
|
||||
|
||||
List<DataProvider<Boolean>> unsatisifiedProviders = new ArrayList<>(dataProviders.getPlayerMethodsByType(Boolean.class));
|
||||
Set<DataProvider<Boolean>> satisfied = new HashSet<>();
|
||||
|
||||
do {
|
||||
// Clear conditions satisfied in previous loop
|
||||
satisfied.clear();
|
||||
// Loop through all unsatisfied providers to see if more conditions are satisfied
|
||||
for (DataProvider<Boolean> booleanProvider : unsatisifiedProviders) {
|
||||
Optional<String> condition = booleanProvider.getProviderInformation().getCondition();
|
||||
if (condition.isPresent() && !providedConditions.contains(condition.get())) {
|
||||
continue; // Condition not met
|
||||
}
|
||||
|
||||
Optional<String> providedCondition = BooleanDataProvider.getProvidedCondition(booleanProvider);
|
||||
|
||||
MethodWrapper<Boolean> method = booleanProvider.getMethod();
|
||||
Boolean result = getMethodResult(
|
||||
() -> method.callMethod(extension, playerUUID, playerName),
|
||||
throwable -> pluginName + " has invalid implementation, method " + method.getMethodName() + " threw exception: " + throwable.toString()
|
||||
);
|
||||
if (result == null) {
|
||||
satisfied.add(booleanProvider); // Prevents further attempts to call this provider for this player.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (result && providedCondition.isPresent()) {
|
||||
providedConditions.add(providedCondition.get()); // The condition was fulfilled for this player.
|
||||
}
|
||||
|
||||
satisfied.add(booleanProvider); // Prevents further attempts to call this provider for this player.
|
||||
database.executeTransaction(new StoreBooleanProviderTransaction(booleanProvider, providedCondition.orElse(null), serverUUID));
|
||||
database.executeTransaction(new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
}
|
||||
// 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 providedConditions;
|
||||
}
|
||||
|
||||
private <T> T getMethodResult(Callable<T> callable, Function<Throwable, String> errorMsg) {
|
||||
try {
|
||||
return callable.call();
|
||||
} catch (Exception | NoSuchFieldError | NoSuchMethodError e) {
|
||||
logger.warn(errorMsg.apply(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
||||
import com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreDataProviderTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerDoubleResultTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerPercentageResultTransaction;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Gathers DoubleProvider and PercentageProvider method data.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
class DoubleAndPercentageProviderValueGatherer {
|
||||
|
||||
private final String pluginName;
|
||||
private final DataExtension extension;
|
||||
private final UUID serverUUID;
|
||||
|
||||
private final Database database;
|
||||
private final DataProviders dataProviders;
|
||||
private final PluginLogger logger;
|
||||
|
||||
DoubleAndPercentageProviderValueGatherer(
|
||||
String pluginName, DataExtension extension,
|
||||
UUID serverUUID, Database database,
|
||||
DataProviders dataProviders,
|
||||
PluginLogger logger
|
||||
) {
|
||||
this.pluginName = pluginName;
|
||||
this.extension = extension;
|
||||
this.serverUUID = serverUUID;
|
||||
this.database = database;
|
||||
this.dataProviders = dataProviders;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
void gatherDoubleData(UUID playerUUID, String playerName, Set<String> providedConditions) {
|
||||
for (DataProvider<Double> doubleProvider : dataProviders.getPlayerMethodsByType(Double.class)) {
|
||||
Optional<String> condition = doubleProvider.getProviderInformation().getCondition();
|
||||
if (condition.isPresent() && !providedConditions.contains(condition.get())) {
|
||||
continue; // Condition not met
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
database.executeTransaction(new StoreDataProviderTransaction<>(doubleProvider, serverUUID));
|
||||
|
||||
if (doubleProvider instanceof PercentageDataProvider) {
|
||||
database.executeTransaction(new StorePlayerDoubleResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
} else {
|
||||
database.executeTransaction(new StorePlayerPercentageResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T getMethodResult(Callable<T> callable, Function<Throwable, String> errorMsg) {
|
||||
try {
|
||||
return callable.call();
|
||||
} catch (Exception | NoSuchFieldError | NoSuchMethodError e) {
|
||||
logger.warn(errorMsg.apply(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.FormatType;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
||||
import com.djrapitops.plan.extension.implementation.providers.NumberDataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreNumberProviderTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerNumberResultTransaction;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Gathers NumberProvider method data.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
class NumberProviderValueGatherer {
|
||||
|
||||
private final String pluginName;
|
||||
private final DataExtension extension;
|
||||
private final UUID serverUUID;
|
||||
|
||||
private final Database database;
|
||||
private final DataProviders dataProviders;
|
||||
private final PluginLogger logger;
|
||||
|
||||
NumberProviderValueGatherer(
|
||||
String pluginName, DataExtension extension,
|
||||
UUID serverUUID, Database database,
|
||||
DataProviders dataProviders,
|
||||
PluginLogger logger
|
||||
) {
|
||||
this.pluginName = pluginName;
|
||||
this.extension = extension;
|
||||
this.serverUUID = serverUUID;
|
||||
this.database = database;
|
||||
this.dataProviders = dataProviders;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
void gatherNumberData(UUID playerUUID, String playerName, Set<String> providedConditions) {
|
||||
for (DataProvider<Long> numberProvider : dataProviders.getPlayerMethodsByType(Long.class)) {
|
||||
Optional<String> condition = numberProvider.getProviderInformation().getCondition();
|
||||
if (condition.isPresent() && !providedConditions.contains(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 StoreNumberProviderTransaction(numberProvider, formatType, serverUUID));
|
||||
database.executeTransaction(new StorePlayerNumberResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T getMethodResult(Callable<T> callable, Function<Throwable, String> errorMsg) {
|
||||
try {
|
||||
return callable.call();
|
||||
} catch (Exception | NoSuchFieldError | NoSuchMethodError e) {
|
||||
logger.warn(errorMsg.apply(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -14,23 +14,21 @@
|
||||
* 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;
|
||||
package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
import com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.*;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerBooleanResultTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.DataProviderExtractor;
|
||||
import com.djrapitops.plan.extension.implementation.PluginTab;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StorePluginTabTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StorePluginTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveInvalidResultsTransaction;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -78,41 +76,37 @@ public class ProviderValueGatherer {
|
||||
|
||||
// TODO implement after storage
|
||||
database.executeTransaction(new RemoveInvalidResultsTransaction(pluginName, serverUUID, extractor.getInvalidatedMethods()));
|
||||
// TODO remove data in db that are updated with a 'false' condition
|
||||
}
|
||||
|
||||
public void updateValues(UUID playerUUID, String playerName) {
|
||||
gatherBooleanData(playerUUID, playerName);
|
||||
Set<String> providedConditions = gatherBooleanData(playerUUID, playerName);
|
||||
gatherValueData(playerUUID, playerName, providedConditions);
|
||||
}
|
||||
|
||||
private void gatherBooleanData(UUID playerUUID, String playerName) {
|
||||
String pluginName = extractor.getPluginName();
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
Database database = dbSystem.getDatabase();
|
||||
DataProviders dataProviders = extractor.getDataProviders();
|
||||
Set<String> providedConditions = new HashSet<>();
|
||||
private Set<String> gatherBooleanData(UUID playerUUID, String playerName) {
|
||||
return new BooleanProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
).gatherBooleanData(playerUUID, playerName);
|
||||
}
|
||||
|
||||
// TODO parse condition tree and traverse based on that.
|
||||
for (DataProvider<Boolean> booleanProvider : dataProviders.getPlayerMethodsByType(Boolean.class)) {
|
||||
Optional<String> providedCondition = Optional.empty();
|
||||
if (booleanProvider instanceof BooleanDataProvider) {
|
||||
providedCondition = ((BooleanDataProvider) booleanProvider).getProvidedCondition();
|
||||
}
|
||||
MethodWrapper<Boolean> method = booleanProvider.getMethod();
|
||||
|
||||
boolean result;
|
||||
try {
|
||||
result = method.callMethod(extension, playerUUID, playerName);
|
||||
} catch (Exception | NoSuchFieldError | NoSuchMethodError e) {
|
||||
logger.warn(pluginName + " has invalid implementation, method " + method.getMethodName() + " threw exception: " + e.toString());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (result && providedCondition.isPresent()) {
|
||||
providedConditions.add(providedCondition.get());
|
||||
}
|
||||
|
||||
database.executeTransaction(new StoreBooleanProviderTransaction(booleanProvider, providedCondition.orElse(null), serverInfo.getServerUUID()));
|
||||
database.executeTransaction(new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
}
|
||||
private void gatherValueData(UUID playerUUID, String playerName, Set<String> providedConditions) {
|
||||
new NumberProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
).gatherNumberData(playerUUID, playerName, providedConditions);
|
||||
new DoubleAndPercentageProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
).gatherDoubleData(playerUUID, playerName, providedConditions);
|
||||
new StringProviderValueGatherer(
|
||||
extractor.getPluginName(), extension,
|
||||
serverInfo.getServerUUID(), dbSystem.getDatabase(),
|
||||
extractor.getDataProviders(), logger
|
||||
).gatherStringData(playerUUID, playerName, providedConditions);
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreDataProviderTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerStringResultTransaction;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Gathers StringProvider method data.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
class StringProviderValueGatherer {
|
||||
|
||||
private final String pluginName;
|
||||
private final DataExtension extension;
|
||||
private final UUID serverUUID;
|
||||
|
||||
private final Database database;
|
||||
private final DataProviders dataProviders;
|
||||
private final PluginLogger logger;
|
||||
|
||||
StringProviderValueGatherer(
|
||||
String pluginName, DataExtension extension,
|
||||
UUID serverUUID, Database database,
|
||||
DataProviders dataProviders,
|
||||
PluginLogger logger
|
||||
) {
|
||||
this.pluginName = pluginName;
|
||||
this.extension = extension;
|
||||
this.serverUUID = serverUUID;
|
||||
this.database = database;
|
||||
this.dataProviders = dataProviders;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
void gatherStringData(UUID playerUUID, String playerName, Set<String> providedConditions) {
|
||||
for (DataProvider<String> stringProvider : dataProviders.getPlayerMethodsByType(String.class)) {
|
||||
Optional<String> condition = stringProvider.getProviderInformation().getCondition();
|
||||
if (condition.isPresent() && !providedConditions.contains(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;
|
||||
}
|
||||
|
||||
database.executeTransaction(new StoreDataProviderTransaction<>(stringProvider, serverUUID));
|
||||
database.executeTransaction(new StorePlayerStringResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T getMethodResult(Callable<T> callable, Function<Throwable, String> errorMsg) {
|
||||
try {
|
||||
return callable.call();
|
||||
} catch (Exception | NoSuchFieldError | NoSuchMethodError e) {
|
||||
logger.warn(errorMsg.apply(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
* 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;
|
||||
package com.djrapitops.plan.extension.implementation.storage.transactions.providers;
|
||||
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.providers;
|
||||
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Transaction to store information about a {@link DataProvider} that has no extra info.
|
||||
* <p>
|
||||
* Includes:
|
||||
* {@link com.djrapitops.plan.extension.implementation.providers.DoubleDataProvider}.
|
||||
* {@link com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider}.
|
||||
* {@link com.djrapitops.plan.extension.implementation.providers.StringDataProvider}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class StoreDataProviderTransaction<T> extends Transaction {
|
||||
|
||||
private final DataProvider<T> provider;
|
||||
private final UUID serverUUID;
|
||||
|
||||
public StoreDataProviderTransaction(DataProvider<T> provider, UUID serverUUID) {
|
||||
this.provider = provider;
|
||||
this.serverUUID = serverUUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
ProviderInformation providerInformation = provider.getProviderInformation();
|
||||
|
||||
// TODO Store provider in a table
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.providers;
|
||||
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import com.djrapitops.plan.extension.FormatType;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Transaction to store information about a {@link com.djrapitops.plan.extension.implementation.providers.NumberDataProvider}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class StoreNumberProviderTransaction<T> extends Transaction {
|
||||
|
||||
private final DataProvider<Long> provider;
|
||||
private final FormatType formatType;
|
||||
private final UUID serverUUID;
|
||||
|
||||
public StoreNumberProviderTransaction(DataProvider<Long> provider, FormatType formatType, UUID serverUUID) {
|
||||
this.provider = provider;
|
||||
this.formatType = formatType;
|
||||
this.serverUUID = serverUUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
ProviderInformation providerInformation = provider.getProviderInformation();
|
||||
|
||||
// TODO Store provider in a table
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
* 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;
|
||||
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
||||
|
||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
|
@ -21,7 +21,7 @@ import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Transaction to store
|
||||
* Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 StorePlayerDoubleResultTransaction extends Transaction {
|
||||
|
||||
private final String pluginName;
|
||||
private final UUID serverUUID;
|
||||
private final String methodName;
|
||||
private final UUID playerUUID;
|
||||
|
||||
private final double value;
|
||||
|
||||
public StorePlayerDoubleResultTransaction(String pluginName, UUID serverUUID, String methodName, UUID playerUUID, double value) {
|
||||
this.pluginName = pluginName;
|
||||
this.serverUUID = serverUUID;
|
||||
this.methodName = methodName;
|
||||
this.playerUUID = playerUUID;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
// TODO Store data in a table
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 StorePlayerNumberResultTransaction extends Transaction {
|
||||
|
||||
private final String pluginName;
|
||||
private final UUID serverUUID;
|
||||
private final String methodName;
|
||||
private final UUID playerUUID;
|
||||
|
||||
private final long value;
|
||||
|
||||
public StorePlayerNumberResultTransaction(String pluginName, UUID serverUUID, String methodName, UUID playerUUID, long value) {
|
||||
this.pluginName = pluginName;
|
||||
this.serverUUID = serverUUID;
|
||||
this.methodName = methodName;
|
||||
this.playerUUID = playerUUID;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
// TODO Store data in a table
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 StorePlayerPercentageResultTransaction extends Transaction {
|
||||
|
||||
private final String pluginName;
|
||||
private final UUID serverUUID;
|
||||
private final String methodName;
|
||||
private final UUID playerUUID;
|
||||
|
||||
private final double value;
|
||||
|
||||
public StorePlayerPercentageResultTransaction(String pluginName, UUID serverUUID, String methodName, UUID playerUUID, double value) {
|
||||
this.pluginName = pluginName;
|
||||
this.serverUUID = serverUUID;
|
||||
this.methodName = methodName;
|
||||
this.playerUUID = playerUUID;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
// TODO Store data in a table
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.StringDataProvider}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class StorePlayerStringResultTransaction extends Transaction {
|
||||
|
||||
private final String pluginName;
|
||||
private final UUID serverUUID;
|
||||
private final String methodName;
|
||||
private final UUID playerUUID;
|
||||
|
||||
private final String value;
|
||||
|
||||
public StorePlayerStringResultTransaction(String pluginName, UUID serverUUID, String methodName, UUID playerUUID, String value) {
|
||||
this.pluginName = pluginName;
|
||||
this.serverUUID = serverUUID;
|
||||
this.methodName = methodName;
|
||||
this.playerUUID = playerUUID;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
// TODO Store data in a table
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user