mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-09 21:38:15 +02:00
Refactored more Gatherers
Now all "non special" gatherers have been combined to use Gatherer interface inside ProviderValueGatherer Two gatherers are not yet abstracted: - BooleanProviderValueGatherer, returns Conditions - TableProviderValueGatherer, different provider save§ This removes a lot of duplicate code that was pretty difficult to understand due to the complexity of the functional interfaces inside the classes
This commit is contained in:
parent
f438366adc
commit
6a0c25edd5
@ -128,7 +128,7 @@ public class DataProviderExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private <T extends Annotation> void extractProviders(PluginInfo pluginInfo, Map<Method, Tab> tabs, Map<Method, Conditional> conditions, Class<T> ofKind, DataProviderFactory<T> factory) {
|
private <T extends Annotation> void extractProviders(PluginInfo pluginInfo, Map<Method, Tab> tabs, Map<Method, Conditional> conditions, Class<T> ofKind, DataProviderFactory<T> factory) {
|
||||||
String pluginName = extractor.getPluginInfo().name();
|
String pluginName = pluginInfo.name();
|
||||||
|
|
||||||
for (Map.Entry<Method, T> entry : extractor.getMethodAnnotations().getMethodAnnotations(ofKind).entrySet()) {
|
for (Map.Entry<Method, T> entry : extractor.getMethodAnnotations().getMethodAnnotations(ofKind).entrySet()) {
|
||||||
Method method = entry.getKey();
|
Method method = entry.getKey();
|
||||||
|
@ -25,23 +25,39 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface Parameters {
|
public interface Parameters {
|
||||||
static Parameters player(UUID playerUUID, String playerName) {
|
static Parameters player(UUID serverUUID, UUID playerUUID, String playerName) {
|
||||||
return new PlayerParameters(playerUUID, playerName);
|
return new PlayerParameters(serverUUID, playerUUID, playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Parameters server() {
|
static Parameters server(UUID serverUUID) {
|
||||||
return new ServerParameters();
|
return new ServerParameters(serverUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Parameters group(String groupName) {
|
static Parameters group(UUID serverUUID, String groupName) {
|
||||||
return new GroupParameters(groupName);
|
return new GroupParameters(serverUUID, groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object call(DataExtension extension, Method method) throws InvocationTargetException, IllegalAccessException;
|
Object call(DataExtension extension, Method method) throws InvocationTargetException, IllegalAccessException;
|
||||||
|
|
||||||
MethodType getMethodType();
|
MethodType getMethodType();
|
||||||
|
|
||||||
|
UUID getServerUUID();
|
||||||
|
|
||||||
|
default UUID getPlayerUUID() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
class ServerParameters implements Parameters {
|
class ServerParameters implements Parameters {
|
||||||
|
private final UUID serverUUID;
|
||||||
|
|
||||||
|
public ServerParameters(UUID serverUUID) {
|
||||||
|
this.serverUUID = serverUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getServerUUID() {
|
||||||
|
return serverUUID;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object call(DataExtension extension, Method method) throws InvocationTargetException, IllegalAccessException {
|
public Object call(DataExtension extension, Method method) throws InvocationTargetException, IllegalAccessException {
|
||||||
return method.invoke(extension);
|
return method.invoke(extension);
|
||||||
@ -54,14 +70,24 @@ public interface Parameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PlayerParameters implements Parameters {
|
class PlayerParameters implements Parameters {
|
||||||
|
private final UUID serverUUID;
|
||||||
private final UUID playerUUID;
|
private final UUID playerUUID;
|
||||||
private final String playerName;
|
private final String playerName;
|
||||||
|
|
||||||
public PlayerParameters(UUID playerUUID, String playerName) {
|
public PlayerParameters(UUID serverUUID, UUID playerUUID, String playerName) {
|
||||||
|
this.serverUUID = serverUUID;
|
||||||
this.playerUUID = playerUUID;
|
this.playerUUID = playerUUID;
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID getServerUUID() {
|
||||||
|
return serverUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getPlayerUUID() {
|
||||||
|
return playerUUID;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object call(DataExtension extension, Method method) throws InvocationTargetException, IllegalAccessException {
|
public Object call(DataExtension extension, Method method) throws InvocationTargetException, IllegalAccessException {
|
||||||
Class<?> parameterType = method.getParameterTypes()[0];
|
Class<?> parameterType = method.getParameterTypes()[0];
|
||||||
@ -79,12 +105,18 @@ public interface Parameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class GroupParameters implements Parameters {
|
class GroupParameters implements Parameters {
|
||||||
|
private final UUID serverUUID;
|
||||||
private final String groupName;
|
private final String groupName;
|
||||||
|
|
||||||
public GroupParameters(String groupName) {
|
public GroupParameters(UUID serverUUID, String groupName) {
|
||||||
|
this.serverUUID = serverUUID;
|
||||||
this.groupName = groupName;
|
this.groupName = groupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID getServerUUID() {
|
||||||
|
return serverUUID;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object call(DataExtension extension, Method method) throws InvocationTargetException, IllegalAccessException {
|
public Object call(DataExtension extension, Method method) throws InvocationTargetException, IllegalAccessException {
|
||||||
Group group = this::getGroupName;
|
Group group = this::getGroupName;
|
||||||
|
@ -30,7 +30,7 @@ import java.lang.reflect.Method;
|
|||||||
*/
|
*/
|
||||||
public class PercentageDataProvider extends DataProvider<Double> {
|
public class PercentageDataProvider extends DataProvider<Double> {
|
||||||
|
|
||||||
// TODO Remove need for instanceof in DoubleAndPercentageProviderGatherer
|
// TODO Remove need for instanceof PercentageDataProvider
|
||||||
|
|
||||||
private PercentageDataProvider(ProviderInformation providerInformation, MethodWrapper<Double> methodWrapper) {
|
private PercentageDataProvider(ProviderInformation providerInformation, MethodWrapper<Double> methodWrapper) {
|
||||||
super(providerInformation, methodWrapper);
|
super(providerInformation, methodWrapper);
|
||||||
|
@ -64,19 +64,19 @@ class BooleanProviderValueGatherer {
|
|||||||
Conditions gatherBooleanDataOfPlayer(UUID playerUUID, String playerName) {
|
Conditions gatherBooleanDataOfPlayer(UUID playerUUID, String playerName) {
|
||||||
Conditions conditions = new Conditions();
|
Conditions conditions = new Conditions();
|
||||||
|
|
||||||
List<DataProvider<Boolean>> unsatisifiedProviders = new ArrayList<>(dataProviders.getPlayerMethodsByType(Boolean.class));
|
List<DataProvider<Boolean>> unsatisfiedProviders = new ArrayList<>(dataProviders.getPlayerMethodsByType(Boolean.class));
|
||||||
Set<DataProvider<Boolean>> satisfied;
|
Set<DataProvider<Boolean>> satisfied;
|
||||||
|
|
||||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||||
// Same with Method result store transaction creation
|
// Same with Method result store transaction creation
|
||||||
Function<MethodWrapper<Boolean>, Callable<Boolean>> methodCaller = method -> () -> method.callMethod(extension, Parameters.player(playerUUID, playerName));
|
Function<MethodWrapper<Boolean>, Callable<Boolean>> methodCaller = method -> () -> method.callMethod(extension, Parameters.player(serverUUID, playerUUID, playerName));
|
||||||
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTrancationCreator = (method, result) -> new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
|
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTrancationCreator = (method, result) -> new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// Loop through all unsatisfied providers to see if more conditions are satisfied
|
// Loop through all unsatisfied providers to see if more conditions are satisfied
|
||||||
satisfied = attemptToSatisfyMoreConditionsAndStoreResults(methodCaller, storeTrancationCreator, conditions, unsatisifiedProviders);
|
satisfied = attemptToSatisfyMoreConditionsAndStoreResults(methodCaller, storeTrancationCreator, conditions, unsatisfiedProviders);
|
||||||
// Remove now satisfied Providers so that they are not called again
|
// Remove now satisfied Providers so that they are not called again
|
||||||
unsatisifiedProviders.removeAll(satisfied);
|
unsatisfiedProviders.removeAll(satisfied);
|
||||||
// If no new conditions could be satisfied, stop looping.
|
// If no new conditions could be satisfied, stop looping.
|
||||||
} while (!satisfied.isEmpty());
|
} while (!satisfied.isEmpty());
|
||||||
|
|
||||||
@ -86,19 +86,19 @@ class BooleanProviderValueGatherer {
|
|||||||
Conditions gatherBooleanDataOfServer() {
|
Conditions gatherBooleanDataOfServer() {
|
||||||
Conditions conditions = new Conditions();
|
Conditions conditions = new Conditions();
|
||||||
|
|
||||||
List<DataProvider<Boolean>> unsatisifiedProviders = new ArrayList<>(dataProviders.getServerMethodsByType(Boolean.class));
|
List<DataProvider<Boolean>> unsatisfiedProviders = new ArrayList<>(dataProviders.getServerMethodsByType(Boolean.class));
|
||||||
Set<DataProvider<Boolean>> satisfied;
|
Set<DataProvider<Boolean>> satisfied;
|
||||||
|
|
||||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||||
// Same with Method result store transaction creation
|
// Same with Method result store transaction creation
|
||||||
Function<MethodWrapper<Boolean>, Callable<Boolean>> methodCaller = method -> () -> method.callMethod(extension, Parameters.server());
|
Function<MethodWrapper<Boolean>, Callable<Boolean>> methodCaller = method -> () -> method.callMethod(extension, Parameters.server(serverUUID));
|
||||||
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTransactionCreator = (method, result) -> new StoreServerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), result);
|
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTransactionCreator = (method, result) -> new StoreServerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), result);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// Loop through all unsatisfied providers to see if more conditions are satisfied
|
// Loop through all unsatisfied providers to see if more conditions are satisfied
|
||||||
satisfied = attemptToSatisfyMoreConditionsAndStoreResults(methodCaller, storeTransactionCreator, conditions, unsatisifiedProviders);
|
satisfied = attemptToSatisfyMoreConditionsAndStoreResults(methodCaller, storeTransactionCreator, conditions, unsatisfiedProviders);
|
||||||
// Remove now satisfied Providers so that they are not called again
|
// Remove now satisfied Providers so that they are not called again
|
||||||
unsatisifiedProviders.removeAll(satisfied);
|
unsatisfiedProviders.removeAll(satisfied);
|
||||||
// If no new conditions could be satisfied, stop looping.
|
// If no new conditions could be satisfied, stop looping.
|
||||||
} while (!satisfied.isEmpty());
|
} while (!satisfied.isEmpty());
|
||||||
|
|
||||||
@ -108,10 +108,10 @@ class BooleanProviderValueGatherer {
|
|||||||
private Set<DataProvider<Boolean>> attemptToSatisfyMoreConditionsAndStoreResults(
|
private Set<DataProvider<Boolean>> attemptToSatisfyMoreConditionsAndStoreResults(
|
||||||
Function<MethodWrapper<Boolean>, Callable<Boolean>> methodCaller,
|
Function<MethodWrapper<Boolean>, Callable<Boolean>> methodCaller,
|
||||||
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTransactionCreator,
|
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTransactionCreator,
|
||||||
Conditions conditions, List<DataProvider<Boolean>> unsatisifiedProviders
|
Conditions conditions, List<DataProvider<Boolean>> unsatisfiedProviders
|
||||||
) {
|
) {
|
||||||
Set<DataProvider<Boolean>> satisfied = new HashSet<>();
|
Set<DataProvider<Boolean>> satisfied = new HashSet<>();
|
||||||
for (DataProvider<Boolean> booleanProvider : unsatisifiedProviders) {
|
for (DataProvider<Boolean> booleanProvider : unsatisfiedProviders) {
|
||||||
ProviderInformation information = booleanProvider.getProviderInformation();
|
ProviderInformation information = booleanProvider.getProviderInformation();
|
||||||
|
|
||||||
Optional<String> condition = information.getCondition();
|
Optional<String> condition = information.getCondition();
|
||||||
|
@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.exceptions.DataExtensionMethodCallException;
|
|
||||||
import com.djrapitops.plan.extension.DataExtension;
|
|
||||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
|
||||||
import com.djrapitops.plan.extension.implementation.providers.*;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction;
|
|
||||||
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.plan.storage.database.Database;
|
|
||||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
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;
|
|
||||||
|
|
||||||
DoubleAndPercentageProviderValueGatherer(
|
|
||||||
String pluginName, DataExtension extension,
|
|
||||||
UUID serverUUID, Database database,
|
|
||||||
DataProviders dataProviders
|
|
||||||
) {
|
|
||||||
this.pluginName = pluginName;
|
|
||||||
this.extension = extension;
|
|
||||||
this.serverUUID = serverUUID;
|
|
||||||
this.database = database;
|
|
||||||
this.dataProviders = dataProviders;
|
|
||||||
}
|
|
||||||
|
|
||||||
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, Parameters.player(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)) {
|
|
||||||
gatherDoubleDataOfProvider(methodCaller, percStoreTransactionCreator, doubleStoreTransactionCreator, conditions, doubleProvider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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, Parameters.server());
|
|
||||||
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);
|
|
||||||
|
|
||||||
for (DataProvider<Double> doubleProvider : dataProviders.getServerMethodsByType(Double.class)) {
|
|
||||||
gatherDoubleDataOfProvider(methodCaller, percStoreTransactionCreator, doubleStoreTransactionCreator, conditions, doubleProvider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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), method);
|
|
||||||
if (result == null) {
|
|
||||||
return; // Error during call
|
|
||||||
}
|
|
||||||
|
|
||||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
|
||||||
database.executeTransaction(new StoreProviderTransaction(doubleProvider, serverUUID));
|
|
||||||
|
|
||||||
if (doubleProvider instanceof PercentageDataProvider) {
|
|
||||||
database.executeTransaction(percStoreTransactionCreator.apply(method, result));
|
|
||||||
} else {
|
|
||||||
database.executeTransaction(doubleStoreTransactionCreator.apply(method, result));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> T getMethodResult(Callable<T> callable, MethodWrapper<T> method) {
|
|
||||||
try {
|
|
||||||
return callable.call();
|
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
|
||||||
throw new DataExtensionMethodCallException(e, pluginName, method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.exceptions.DataExtensionMethodCallException;
|
|
||||||
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.DataProviders;
|
|
||||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
|
||||||
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerGroupsResultTransaction;
|
|
||||||
import com.djrapitops.plan.storage.database.Database;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gathers GroupProvider method data.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
class GroupProviderValueGatherer {
|
|
||||||
|
|
||||||
private final String pluginName;
|
|
||||||
private final DataExtension extension;
|
|
||||||
private final UUID serverUUID;
|
|
||||||
|
|
||||||
private final Database database;
|
|
||||||
private final DataProviders dataProviders;
|
|
||||||
|
|
||||||
GroupProviderValueGatherer(
|
|
||||||
String pluginName, DataExtension extension,
|
|
||||||
UUID serverUUID, Database database,
|
|
||||||
DataProviders dataProviders
|
|
||||||
) {
|
|
||||||
this.pluginName = pluginName;
|
|
||||||
this.extension = extension;
|
|
||||||
this.serverUUID = serverUUID;
|
|
||||||
this.database = database;
|
|
||||||
this.dataProviders = dataProviders;
|
|
||||||
}
|
|
||||||
|
|
||||||
void gatherGroupDataOfPlayer(UUID playerUUID, String playerName, Conditions conditions) {
|
|
||||||
for (DataProvider<String[]> groupProvider : dataProviders.getPlayerMethodsByType(String[].class)) {
|
|
||||||
gatherGroupDataOfProvider(playerUUID, playerName, conditions, groupProvider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void gatherGroupDataOfProvider(
|
|
||||||
UUID playerUUID, String playerName,
|
|
||||||
Conditions conditions,
|
|
||||||
DataProvider<String[]> groupProvider
|
|
||||||
) {
|
|
||||||
ProviderInformation providerInformation = groupProvider.getProviderInformation();
|
|
||||||
Optional<String> condition = providerInformation.getCondition();
|
|
||||||
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MethodWrapper<String[]> method = groupProvider.getMethod();
|
|
||||||
try {
|
|
||||||
String[] result = method.callMethod(extension, Parameters.player(playerUUID, playerName));
|
|
||||||
if (result == null) {
|
|
||||||
return; // Error during call
|
|
||||||
}
|
|
||||||
|
|
||||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
|
||||||
database.executeTransaction(new StoreProviderTransaction(groupProvider, serverUUID));
|
|
||||||
database.executeTransaction(new StorePlayerGroupsResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
|
||||||
throw new DataExtensionMethodCallException(e, pluginName, method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.exceptions.DataExtensionMethodCallException;
|
|
||||||
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.DataProviders;
|
|
||||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
|
||||||
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerNumberResultTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StoreServerNumberResultTransaction;
|
|
||||||
import com.djrapitops.plan.storage.database.Database;
|
|
||||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
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;
|
|
||||||
|
|
||||||
NumberProviderValueGatherer(
|
|
||||||
String pluginName, DataExtension extension,
|
|
||||||
UUID serverUUID, Database database,
|
|
||||||
DataProviders dataProviders
|
|
||||||
) {
|
|
||||||
this.pluginName = pluginName;
|
|
||||||
this.extension = extension;
|
|
||||||
this.serverUUID = serverUUID;
|
|
||||||
this.database = database;
|
|
||||||
this.dataProviders = dataProviders;
|
|
||||||
}
|
|
||||||
|
|
||||||
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, Parameters.player(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)) {
|
|
||||||
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, Parameters.server());
|
|
||||||
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), method);
|
|
||||||
if (result == null) {
|
|
||||||
return; // Error during call
|
|
||||||
}
|
|
||||||
|
|
||||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
|
||||||
database.executeTransaction(new StoreProviderTransaction(numberProvider, serverUUID));
|
|
||||||
database.executeTransaction(storeTransactionCreator.apply(method, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> T getMethodResult(Callable<T> callable, MethodWrapper<T> method) {
|
|
||||||
try {
|
|
||||||
return callable.call();
|
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
|
||||||
throw new DataExtensionMethodCallException(e, pluginName, method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -30,16 +30,13 @@ import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIc
|
|||||||
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;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveInvalidResultsTransaction;
|
import com.djrapitops.plan.extension.implementation.storage.transactions.results.*;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerNumberResultTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StoreServerNumberResultTransaction;
|
|
||||||
import com.djrapitops.plan.identification.ServerInfo;
|
import com.djrapitops.plan.identification.ServerInfo;
|
||||||
import com.djrapitops.plan.storage.database.DBSystem;
|
import com.djrapitops.plan.storage.database.DBSystem;
|
||||||
import com.djrapitops.plan.storage.database.Database;
|
import com.djrapitops.plan.storage.database.Database;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object that can be called to place data about players to the database.
|
* Object that can be called to place data about players to the database.
|
||||||
@ -57,12 +54,14 @@ public class ProviderValueGatherer {
|
|||||||
|
|
||||||
private final DataProviders dataProviders;
|
private final DataProviders dataProviders;
|
||||||
private final BooleanProviderValueGatherer booleanGatherer;
|
private final BooleanProviderValueGatherer booleanGatherer;
|
||||||
private final DoubleAndPercentageProviderValueGatherer doubleAndPercentageGatherer;
|
|
||||||
private final StringProviderValueGatherer stringGatherer;
|
|
||||||
private final TableProviderValueGatherer tableGatherer;
|
private final TableProviderValueGatherer tableGatherer;
|
||||||
private final GroupProviderValueGatherer groupGatherer;
|
private final Gatherer<Long> serverNumberGatherer;
|
||||||
private Gatherer<Long> serverNumberGatherer;
|
private final Gatherer<Long> playerNumberGatherer;
|
||||||
private Gatherer<Long> playerNumberGatherer;
|
private final Gatherer<Double> serverDoubleGatherer;
|
||||||
|
private final Gatherer<Double> playerDoubleGatherer;
|
||||||
|
private final Gatherer<String> serverStringGatherer;
|
||||||
|
private final Gatherer<String> playerStringGatherer;
|
||||||
|
private final Gatherer<String[]> playerGroupGatherer;
|
||||||
|
|
||||||
public ProviderValueGatherer(
|
public ProviderValueGatherer(
|
||||||
DataExtension extension,
|
DataExtension extension,
|
||||||
@ -83,25 +82,30 @@ public class ProviderValueGatherer {
|
|||||||
booleanGatherer = new BooleanProviderValueGatherer(
|
booleanGatherer = new BooleanProviderValueGatherer(
|
||||||
pluginName, extension, serverUUID, database, dataProviders
|
pluginName, extension, serverUUID, database, dataProviders
|
||||||
);
|
);
|
||||||
NumberProviderValueGatherer numberGatherer = new NumberProviderValueGatherer(
|
|
||||||
pluginName, extension, serverUUID, database, dataProviders
|
|
||||||
);
|
|
||||||
doubleAndPercentageGatherer = new DoubleAndPercentageProviderValueGatherer(
|
|
||||||
pluginName, extension, serverUUID, database, dataProviders
|
|
||||||
);
|
|
||||||
stringGatherer = new StringProviderValueGatherer(
|
|
||||||
pluginName, extension, serverUUID, database, dataProviders
|
|
||||||
);
|
|
||||||
tableGatherer = new TableProviderValueGatherer(
|
tableGatherer = new TableProviderValueGatherer(
|
||||||
pluginName, extension, serverUUID, database, dataProviders
|
pluginName, extension, serverUUID, database, dataProviders
|
||||||
);
|
);
|
||||||
groupGatherer = new GroupProviderValueGatherer(
|
|
||||||
pluginName, extension, serverUUID, database, dataProviders
|
|
||||||
);
|
|
||||||
|
|
||||||
serverNumberGatherer = new Gatherer<>(Long.class,
|
serverNumberGatherer = new Gatherer<>(
|
||||||
StoreProviderTransaction::new,
|
Long.class, StoreServerNumberResultTransaction::new
|
||||||
(provider, result) -> new StoreServerNumberResultTransaction(provider, serverUUID, result)
|
);
|
||||||
|
serverDoubleGatherer = new Gatherer<>(
|
||||||
|
Double.class, StoreServerDoubleResultTransaction::new
|
||||||
|
);
|
||||||
|
serverStringGatherer = new Gatherer<>(
|
||||||
|
String.class, StoreServerStringResultTransaction::new
|
||||||
|
);
|
||||||
|
playerNumberGatherer = new Gatherer<>(
|
||||||
|
Long.class, StorePlayerNumberResultTransaction::new
|
||||||
|
);
|
||||||
|
playerDoubleGatherer = new Gatherer<>(
|
||||||
|
Double.class, StorePlayerDoubleResultTransaction::new
|
||||||
|
);
|
||||||
|
playerStringGatherer = new Gatherer<>(
|
||||||
|
String.class, StorePlayerStringResultTransaction::new
|
||||||
|
);
|
||||||
|
playerGroupGatherer = new Gatherer<>(
|
||||||
|
String[].class, StorePlayerGroupsResultTransaction::new
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,54 +149,37 @@ public class ProviderValueGatherer {
|
|||||||
|
|
||||||
public void updateValues(UUID playerUUID, String playerName) {
|
public void updateValues(UUID playerUUID, String playerName) {
|
||||||
Conditions conditions = booleanGatherer.gatherBooleanDataOfPlayer(playerUUID, playerName);
|
Conditions conditions = booleanGatherer.gatherBooleanDataOfPlayer(playerUUID, playerName);
|
||||||
|
Parameters params = Parameters.player(serverInfo.getServerUUID(), playerUUID, playerName);
|
||||||
Parameters params = Parameters.player(playerUUID, playerName);
|
|
||||||
UUID serverUUID = serverInfo.getServerUUID();
|
|
||||||
playerNumberGatherer = new Gatherer<>(Long.class,
|
|
||||||
StoreProviderTransaction::new,
|
|
||||||
(provider, result) -> new StorePlayerNumberResultTransaction(provider, serverUUID, playerUUID, result) // TODO Sort out this use of playerUUID
|
|
||||||
);
|
|
||||||
playerNumberGatherer.gather(conditions, params);
|
playerNumberGatherer.gather(conditions, params);
|
||||||
doubleAndPercentageGatherer.gatherDoubleDataOfPlayer(playerUUID, playerName, conditions);
|
playerDoubleGatherer.gather(conditions, params);
|
||||||
stringGatherer.gatherStringDataOfPlayer(playerUUID, playerName, conditions);
|
playerStringGatherer.gather(conditions, params);
|
||||||
tableGatherer.gatherTableDataOfPlayer(playerUUID, playerName, conditions);
|
tableGatherer.gatherTableDataOfPlayer(playerUUID, playerName, conditions);
|
||||||
groupGatherer.gatherGroupDataOfPlayer(playerUUID, playerName, conditions);
|
playerGroupGatherer.gather(conditions, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateValues() {
|
public void updateValues() {
|
||||||
Conditions conditions = booleanGatherer.gatherBooleanDataOfServer();
|
Conditions conditions = booleanGatherer.gatherBooleanDataOfServer();
|
||||||
Parameters params = Parameters.server();
|
Parameters params = Parameters.server(serverInfo.getServerUUID());
|
||||||
|
|
||||||
serverNumberGatherer.gather(conditions, params);
|
serverNumberGatherer.gather(conditions, params);
|
||||||
doubleAndPercentageGatherer.gatherDoubleDataOfServer(conditions);
|
serverDoubleGatherer.gather(conditions, params);
|
||||||
stringGatherer.gatherStringDataOfServer(conditions);
|
serverStringGatherer.gather(conditions, params);
|
||||||
tableGatherer.gatherTableDataOfServer(conditions);
|
tableGatherer.gatherTableDataOfServer(conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ProviderTransactionConstructor<T> extends BiFunction<DataProvider<T>, UUID, Transaction> {
|
interface ResultTransactionConstructor<T> {
|
||||||
default Transaction create(DataProvider<T> provider, UUID serverUUID) {
|
Transaction create(DataProvider<T> provider, Parameters parameters, T result);
|
||||||
return apply(provider, serverUUID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ResultTransactionConstructor<T> extends BiFunction<DataProvider<T>, T, Transaction> {
|
|
||||||
default Transaction create(DataProvider<T> provider, T result) {
|
|
||||||
return apply(provider, result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Gatherer<T> {
|
class Gatherer<T> {
|
||||||
private final Class<T> type;
|
private final Class<T> type;
|
||||||
private final ProviderTransactionConstructor<T> providerTransactionConstructor;
|
|
||||||
private final ResultTransactionConstructor<T> resultTransactionConstructor;
|
private final ResultTransactionConstructor<T> resultTransactionConstructor;
|
||||||
|
|
||||||
public Gatherer(
|
public Gatherer(
|
||||||
Class<T> type,
|
Class<T> type,
|
||||||
ProviderTransactionConstructor<T> providerTransactionConstructor,
|
|
||||||
ResultTransactionConstructor<T> resultTransactionConstructor
|
ResultTransactionConstructor<T> resultTransactionConstructor
|
||||||
) {
|
) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.providerTransactionConstructor = providerTransactionConstructor;
|
|
||||||
this.resultTransactionConstructor = resultTransactionConstructor;
|
this.resultTransactionConstructor = resultTransactionConstructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,8 +202,8 @@ public class ProviderValueGatherer {
|
|||||||
|
|
||||||
Database db = dbSystem.getDatabase();
|
Database db = dbSystem.getDatabase();
|
||||||
db.executeTransaction(new StoreIconTransaction(information.getIcon()));
|
db.executeTransaction(new StoreIconTransaction(information.getIcon()));
|
||||||
db.executeTransaction(providerTransactionConstructor.create(provider, serverInfo.getServerUUID()));
|
db.executeTransaction(new StoreProviderTransaction(provider, parameters.getServerUUID()));
|
||||||
db.executeTransaction(resultTransactionConstructor.create(provider, result));
|
db.executeTransaction(resultTransactionConstructor.create(provider, parameters, result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,121 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.exceptions.DataExtensionMethodCallException;
|
|
||||||
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.DataProviders;
|
|
||||||
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
|
|
||||||
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerStringResultTransaction;
|
|
||||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StoreServerStringResultTransaction;
|
|
||||||
import com.djrapitops.plan.storage.database.Database;
|
|
||||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
StringProviderValueGatherer(
|
|
||||||
String pluginName, DataExtension extension,
|
|
||||||
UUID serverUUID, Database database,
|
|
||||||
DataProviders dataProviders
|
|
||||||
) {
|
|
||||||
this.pluginName = pluginName;
|
|
||||||
this.extension = extension;
|
|
||||||
this.serverUUID = serverUUID;
|
|
||||||
this.database = database;
|
|
||||||
this.dataProviders = dataProviders;
|
|
||||||
}
|
|
||||||
|
|
||||||
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, Parameters.player(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)) {
|
|
||||||
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, Parameters.server());
|
|
||||||
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), method);
|
|
||||||
if (result == null) {
|
|
||||||
return; // Error during call
|
|
||||||
}
|
|
||||||
|
|
||||||
result = StringUtils.truncate(result, 50);
|
|
||||||
|
|
||||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
|
||||||
database.executeTransaction(new StoreProviderTransaction(stringProvider, serverUUID));
|
|
||||||
database.executeTransaction(storeTransactionCreator.apply(method, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> T getMethodResult(Callable<T> callable, MethodWrapper<String> method) {
|
|
||||||
try {
|
|
||||||
return callable.call();
|
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
|
||||||
throw new DataExtensionMethodCallException(e, pluginName, method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -67,7 +67,7 @@ class TableProviderValueGatherer {
|
|||||||
void gatherTableDataOfPlayer(UUID playerUUID, String playerName, Conditions conditions) {
|
void gatherTableDataOfPlayer(UUID playerUUID, String playerName, Conditions conditions) {
|
||||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||||
// Same with Method result store transaction creation
|
// Same with Method result store transaction creation
|
||||||
Function<MethodWrapper<Table>, Callable<Table>> methodCaller = method -> () -> method.callMethod(extension, Parameters.player(playerUUID, playerName));
|
Function<MethodWrapper<Table>, Callable<Table>> methodCaller = method -> () -> method.callMethod(extension, Parameters.player(serverUUID, playerUUID, playerName));
|
||||||
BiFunction<MethodWrapper<Table>, Table, Transaction> storeTransactionCreator = (method, result) -> new StorePlayerTableResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
|
BiFunction<MethodWrapper<Table>, Table, Transaction> storeTransactionCreator = (method, result) -> new StorePlayerTableResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
|
||||||
|
|
||||||
for (DataProvider<Table> tableProvider : dataProviders.getPlayerMethodsByType(Table.class)) {
|
for (DataProvider<Table> tableProvider : dataProviders.getPlayerMethodsByType(Table.class)) {
|
||||||
@ -78,7 +78,7 @@ class TableProviderValueGatherer {
|
|||||||
void gatherTableDataOfServer(Conditions conditions) {
|
void gatherTableDataOfServer(Conditions conditions) {
|
||||||
// Method parameters abstracted away so that same method can be used for all parameter types
|
// Method parameters abstracted away so that same method can be used for all parameter types
|
||||||
// Same with Method result store transaction creation
|
// Same with Method result store transaction creation
|
||||||
Function<MethodWrapper<Table>, Callable<Table>> methodCaller = method -> () -> method.callMethod(extension, Parameters.server());
|
Function<MethodWrapper<Table>, Callable<Table>> methodCaller = method -> () -> method.callMethod(extension, Parameters.server(serverUUID));
|
||||||
BiFunction<MethodWrapper<Table>, Table, Transaction> storeTransactionCreator = (method, result) -> new StoreServerTableResultTransaction(pluginName, serverUUID, method.getMethodName(), result);
|
BiFunction<MethodWrapper<Table>, Table, Transaction> storeTransactionCreator = (method, result) -> new StoreServerTableResultTransaction(pluginName, serverUUID, method.getMethodName(), result);
|
||||||
|
|
||||||
for (DataProvider<Table> tableProvider : dataProviders.getServerMethodsByType(Table.class)) {
|
for (DataProvider<Table> tableProvider : dataProviders.getServerMethodsByType(Table.class)) {
|
||||||
|
@ -109,21 +109,6 @@ public class StoreProviderTransaction extends ThrowawayTransaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Executable insertProvider() {
|
private Executable insertProvider() {
|
||||||
/* PROVIDER_NAME
|
|
||||||
PLUGIN_ID
|
|
||||||
|
|
||||||
TEXT
|
|
||||||
DESCRIPTION // Can be null
|
|
||||||
PRIORITY
|
|
||||||
GROUPABLE // default false
|
|
||||||
CONDITION // Can be null, related to @Conditional
|
|
||||||
ICON_ID
|
|
||||||
TAB_ID // Can be null, related to @Tab
|
|
||||||
SHOW_IN_PLAYERS_TABLE // default false
|
|
||||||
HIDDEN // default false, related to @BooleanProvider
|
|
||||||
PROVIDED_CONDITION // Can be null, related to @BooleanProvider
|
|
||||||
FORMAT_TYPE // Can be null, related to @NumberProvider
|
|
||||||
IS_PLAYER_NAME // default false, related to @StringProvider */
|
|
||||||
String sql = "INSERT INTO " + TABLE_NAME + '(' +
|
String sql = "INSERT INTO " + TABLE_NAME + '(' +
|
||||||
PROVIDER_NAME + ',' +
|
PROVIDER_NAME + ',' +
|
||||||
TEXT + ',' +
|
TEXT + ',' +
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||||
@ -28,9 +31,13 @@ import java.util.UUID;
|
|||||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.AND;
|
import static com.djrapitops.plan.storage.database.sql.building.Sql.AND;
|
||||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.WHERE;
|
import static com.djrapitops.plan.storage.database.sql.building.Sql.WHERE;
|
||||||
import static com.djrapitops.plan.storage.database.sql.tables.ExtensionPlayerValueTable.*;
|
import static com.djrapitops.plan.storage.database.sql.tables.ExtensionPlayerValueTable.*;
|
||||||
|
import static com.djrapitops.plan.storage.database.sql.tables.ExtensionServerValueTable.DOUBLE_VALUE;
|
||||||
|
import static com.djrapitops.plan.storage.database.sql.tables.ExtensionServerValueTable.PERCENTAGE_VALUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.DoubleDataProvider}.
|
* Transaction to store method result of.
|
||||||
|
* - {@link com.djrapitops.plan.extension.annotation.DoubleProvider}
|
||||||
|
* - {@link com.djrapitops.plan.extension.annotation.PercentageProvider}
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
@ -42,13 +49,15 @@ public class StorePlayerDoubleResultTransaction extends ThrowawayTransaction {
|
|||||||
private final UUID playerUUID;
|
private final UUID playerUUID;
|
||||||
|
|
||||||
private final double value;
|
private final double value;
|
||||||
|
private final boolean percentage;
|
||||||
|
|
||||||
public StorePlayerDoubleResultTransaction(String pluginName, UUID serverUUID, String providerName, UUID playerUUID, double value) {
|
public StorePlayerDoubleResultTransaction(DataProvider<Double> provider, Parameters parameters, double value) {
|
||||||
this.pluginName = pluginName;
|
this.pluginName = provider.getProviderInformation().getPluginName();
|
||||||
this.serverUUID = serverUUID;
|
this.providerName = provider.getProviderInformation().getName();
|
||||||
this.providerName = providerName;
|
this.serverUUID = parameters.getServerUUID();
|
||||||
this.playerUUID = playerUUID;
|
this.playerUUID = parameters.getPlayerUUID();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
this.percentage = provider instanceof PercentageDataProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,7 +77,7 @@ public class StorePlayerDoubleResultTransaction extends ThrowawayTransaction {
|
|||||||
private Executable updateValue() {
|
private Executable updateValue() {
|
||||||
String sql = "UPDATE " + TABLE_NAME +
|
String sql = "UPDATE " + TABLE_NAME +
|
||||||
" SET " +
|
" SET " +
|
||||||
DOUBLE_VALUE + "=?" +
|
(percentage ? PERCENTAGE_VALUE : DOUBLE_VALUE) + "=?" +
|
||||||
WHERE + USER_UUID + "=?" +
|
WHERE + USER_UUID + "=?" +
|
||||||
AND + PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID;
|
AND + PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID;
|
||||||
|
|
||||||
@ -84,7 +93,7 @@ public class StorePlayerDoubleResultTransaction extends ThrowawayTransaction {
|
|||||||
|
|
||||||
private Executable insertValue() {
|
private Executable insertValue() {
|
||||||
String sql = "INSERT INTO " + TABLE_NAME + "(" +
|
String sql = "INSERT INTO " + TABLE_NAME + "(" +
|
||||||
DOUBLE_VALUE + "," +
|
(percentage ? PERCENTAGE_VALUE : DOUBLE_VALUE) + "," +
|
||||||
USER_UUID + "," +
|
USER_UUID + "," +
|
||||||
PROVIDER_ID +
|
PROVIDER_ID +
|
||||||
") VALUES (?,?," + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID + ")";
|
") VALUES (?,?," + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID + ")";
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionGroupsTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionGroupsTable;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
@ -43,11 +45,11 @@ public class StorePlayerGroupsResultTransaction extends ThrowawayTransaction {
|
|||||||
|
|
||||||
private final String[] value;
|
private final String[] value;
|
||||||
|
|
||||||
public StorePlayerGroupsResultTransaction(String pluginName, UUID serverUUID, String providerName, UUID playerUUID, String[] value) {
|
public StorePlayerGroupsResultTransaction(DataProvider<String[]> provider, Parameters parameters, String[] value) {
|
||||||
this.pluginName = pluginName;
|
this.pluginName = provider.getProviderInformation().getPluginName();
|
||||||
this.serverUUID = serverUUID;
|
this.providerName = provider.getProviderInformation().getName();
|
||||||
this.providerName = providerName;
|
this.serverUUID = parameters.getServerUUID();
|
||||||
this.playerUUID = playerUUID;
|
this.playerUUID = parameters.getPlayerUUID();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
||||||
|
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||||
@ -44,18 +45,14 @@ public class StorePlayerNumberResultTransaction extends ThrowawayTransaction {
|
|||||||
|
|
||||||
private final long value;
|
private final long value;
|
||||||
|
|
||||||
public StorePlayerNumberResultTransaction(String pluginName, UUID serverUUID, String providerName, UUID playerUUID, long value) {
|
public StorePlayerNumberResultTransaction(DataProvider<Long> provider, Parameters parameters, long value) {
|
||||||
this.pluginName = pluginName;
|
this.pluginName = provider.getProviderInformation().getPluginName();
|
||||||
this.serverUUID = serverUUID;
|
this.providerName = provider.getProviderInformation().getName();
|
||||||
this.providerName = providerName;
|
this.serverUUID = parameters.getServerUUID();
|
||||||
this.playerUUID = playerUUID;
|
this.playerUUID = parameters.getPlayerUUID();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorePlayerNumberResultTransaction(DataProvider<Long> provider, UUID serverUUID, UUID playerUUID, long value) {
|
|
||||||
this(provider.getProviderInformation().getPluginName(), serverUUID, provider.getProviderInformation().getName(), playerUUID, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void performOperations() {
|
protected void performOperations() {
|
||||||
execute(storeValue());
|
execute(storeValue());
|
||||||
|
@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.storage.database.sql.tables.ExtensionProviderTable;
|
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
|
||||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
|
||||||
import com.djrapitops.plan.storage.database.transactions.ThrowawayTransaction;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.AND;
|
|
||||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.WHERE;
|
|
||||||
import static com.djrapitops.plan.storage.database.sql.tables.ExtensionPlayerValueTable.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider}.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class StorePlayerPercentageResultTransaction extends ThrowawayTransaction {
|
|
||||||
|
|
||||||
private final String pluginName;
|
|
||||||
private final UUID serverUUID;
|
|
||||||
private final String providerName;
|
|
||||||
private final UUID playerUUID;
|
|
||||||
|
|
||||||
private final double value;
|
|
||||||
|
|
||||||
public StorePlayerPercentageResultTransaction(String pluginName, UUID serverUUID, String providerName, UUID playerUUID, double value) {
|
|
||||||
this.pluginName = pluginName;
|
|
||||||
this.serverUUID = serverUUID;
|
|
||||||
this.providerName = providerName;
|
|
||||||
this.playerUUID = playerUUID;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void performOperations() {
|
|
||||||
execute(storeValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Executable storeValue() {
|
|
||||||
return connection -> {
|
|
||||||
if (!updateValue().execute(connection)) {
|
|
||||||
return insertValue().execute(connection);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private Executable updateValue() {
|
|
||||||
String sql = "UPDATE " + TABLE_NAME +
|
|
||||||
" SET " +
|
|
||||||
PERCENTAGE_VALUE + "=?" +
|
|
||||||
WHERE + USER_UUID + "=?" +
|
|
||||||
AND + PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID;
|
|
||||||
|
|
||||||
return new ExecStatement(sql) {
|
|
||||||
@Override
|
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
|
||||||
statement.setDouble(1, value);
|
|
||||||
statement.setString(2, playerUUID.toString());
|
|
||||||
ExtensionProviderTable.set3PluginValuesToStatement(statement, 3, providerName, pluginName, serverUUID);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private Executable insertValue() {
|
|
||||||
String sql = "INSERT INTO " + TABLE_NAME + "(" +
|
|
||||||
PERCENTAGE_VALUE + "," +
|
|
||||||
USER_UUID + "," +
|
|
||||||
PROVIDER_ID +
|
|
||||||
") VALUES (?,?," + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID + ")";
|
|
||||||
return new ExecStatement(sql) {
|
|
||||||
@Override
|
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
|
||||||
statement.setDouble(1, value);
|
|
||||||
statement.setString(2, playerUUID.toString());
|
|
||||||
ExtensionProviderTable.set3PluginValuesToStatement(statement, 3, providerName, pluginName, serverUUID);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||||
@ -43,11 +45,11 @@ public class StorePlayerStringResultTransaction extends ThrowawayTransaction {
|
|||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
public StorePlayerStringResultTransaction(String pluginName, UUID serverUUID, String providerName, UUID playerUUID, String value) {
|
public StorePlayerStringResultTransaction(DataProvider<String> provider, Parameters parameters, String value) {
|
||||||
this.pluginName = pluginName;
|
this.pluginName = provider.getProviderInformation().getPluginName();
|
||||||
this.serverUUID = serverUUID;
|
this.providerName = provider.getProviderInformation().getName();
|
||||||
this.providerName = providerName;
|
this.serverUUID = parameters.getServerUUID();
|
||||||
this.playerUUID = playerUUID;
|
this.playerUUID = parameters.getPlayerUUID();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||||
@ -40,12 +43,14 @@ public class StoreServerDoubleResultTransaction extends ThrowawayTransaction {
|
|||||||
private final String providerName;
|
private final String providerName;
|
||||||
|
|
||||||
private final double value;
|
private final double value;
|
||||||
|
private final boolean percentage;
|
||||||
|
|
||||||
public StoreServerDoubleResultTransaction(String pluginName, UUID serverUUID, String providerName, double value) {
|
public StoreServerDoubleResultTransaction(DataProvider<Double> provider, Parameters parameters, double value) {
|
||||||
this.pluginName = pluginName;
|
this.pluginName = provider.getProviderInformation().getPluginName();
|
||||||
this.serverUUID = serverUUID;
|
this.providerName = provider.getProviderInformation().getName();
|
||||||
this.providerName = providerName;
|
this.serverUUID = parameters.getServerUUID();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
this.percentage = provider instanceof PercentageDataProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -65,7 +70,7 @@ public class StoreServerDoubleResultTransaction extends ThrowawayTransaction {
|
|||||||
private Executable updateValue() {
|
private Executable updateValue() {
|
||||||
String sql = "UPDATE " + TABLE_NAME +
|
String sql = "UPDATE " + TABLE_NAME +
|
||||||
" SET " +
|
" SET " +
|
||||||
DOUBLE_VALUE + "=?" +
|
(percentage ? PERCENTAGE_VALUE : DOUBLE_VALUE) + "=?" +
|
||||||
WHERE + PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID;
|
WHERE + PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID;
|
||||||
|
|
||||||
return new ExecStatement(sql) {
|
return new ExecStatement(sql) {
|
||||||
@ -79,7 +84,7 @@ public class StoreServerDoubleResultTransaction extends ThrowawayTransaction {
|
|||||||
|
|
||||||
private Executable insertValue() {
|
private Executable insertValue() {
|
||||||
String sql = "INSERT INTO " + TABLE_NAME + "(" +
|
String sql = "INSERT INTO " + TABLE_NAME + "(" +
|
||||||
DOUBLE_VALUE + "," +
|
(percentage ? PERCENTAGE_VALUE : DOUBLE_VALUE) + "," +
|
||||||
PROVIDER_ID +
|
PROVIDER_ID +
|
||||||
") VALUES (?," + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID + ")";
|
") VALUES (?," + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID + ")";
|
||||||
return new ExecStatement(sql) {
|
return new ExecStatement(sql) {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
||||||
|
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||||
@ -42,17 +43,13 @@ public class StoreServerNumberResultTransaction extends ThrowawayTransaction {
|
|||||||
|
|
||||||
private final long value;
|
private final long value;
|
||||||
|
|
||||||
public StoreServerNumberResultTransaction(String pluginName, UUID serverUUID, String providerName, long value) {
|
public StoreServerNumberResultTransaction(DataProvider<Long> provider, Parameters parameters, long value) {
|
||||||
this.pluginName = pluginName;
|
this.pluginName = provider.getProviderInformation().getPluginName();
|
||||||
this.serverUUID = serverUUID;
|
this.providerName = provider.getProviderInformation().getName();
|
||||||
this.providerName = providerName;
|
this.serverUUID = parameters.getServerUUID();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StoreServerNumberResultTransaction(DataProvider<Long> provider, UUID serverUUID, long value) {
|
|
||||||
this(provider.getProviderInformation().getPluginName(), serverUUID, provider.getProviderInformation().getName(), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void performOperations() {
|
protected void performOperations() {
|
||||||
execute(storeValue());
|
execute(storeValue());
|
||||||
|
@ -1,93 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.storage.database.sql.tables.ExtensionProviderTable;
|
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
|
||||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
|
||||||
import com.djrapitops.plan.storage.database.transactions.ThrowawayTransaction;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.WHERE;
|
|
||||||
import static com.djrapitops.plan.storage.database.sql.tables.ExtensionServerValueTable.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider}.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class StoreServerPercentageResultTransaction extends ThrowawayTransaction {
|
|
||||||
|
|
||||||
private final String pluginName;
|
|
||||||
private final UUID serverUUID;
|
|
||||||
private final String providerName;
|
|
||||||
|
|
||||||
private final double value;
|
|
||||||
|
|
||||||
public StoreServerPercentageResultTransaction(String pluginName, UUID serverUUID, String providerName, double value) {
|
|
||||||
this.pluginName = pluginName;
|
|
||||||
this.serverUUID = serverUUID;
|
|
||||||
this.providerName = providerName;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void performOperations() {
|
|
||||||
execute(storeValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Executable storeValue() {
|
|
||||||
return connection -> {
|
|
||||||
if (!updateValue().execute(connection)) {
|
|
||||||
return insertValue().execute(connection);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private Executable updateValue() {
|
|
||||||
String sql = "UPDATE " + TABLE_NAME +
|
|
||||||
" SET " +
|
|
||||||
PERCENTAGE_VALUE + "=?" +
|
|
||||||
WHERE + PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID;
|
|
||||||
|
|
||||||
return new ExecStatement(sql) {
|
|
||||||
@Override
|
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
|
||||||
statement.setDouble(1, value);
|
|
||||||
ExtensionProviderTable.set3PluginValuesToStatement(statement, 2, providerName, pluginName, serverUUID);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private Executable insertValue() {
|
|
||||||
String sql = "INSERT INTO " + TABLE_NAME + "(" +
|
|
||||||
PERCENTAGE_VALUE + "," +
|
|
||||||
PROVIDER_ID +
|
|
||||||
") VALUES (?," + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID + ")";
|
|
||||||
return new ExecStatement(sql) {
|
|
||||||
@Override
|
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
|
||||||
statement.setDouble(1, value);
|
|
||||||
ExtensionProviderTable.set3PluginValuesToStatement(statement, 2, providerName, pluginName, serverUUID);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
package com.djrapitops.plan.extension.implementation.storage.transactions.results;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||||
@ -41,10 +43,10 @@ public class StoreServerStringResultTransaction extends ThrowawayTransaction {
|
|||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
public StoreServerStringResultTransaction(String pluginName, UUID serverUUID, String providerName, String value) {
|
public StoreServerStringResultTransaction(DataProvider<String> provider, Parameters parameters, String value) {
|
||||||
this.pluginName = pluginName;
|
this.pluginName = provider.getProviderInformation().getPluginName();
|
||||||
this.serverUUID = serverUUID;
|
this.providerName = provider.getProviderInformation().getName();
|
||||||
this.providerName = providerName;
|
this.serverUUID = parameters.getServerUUID();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user