Simplified Provider method calling:

- Added an enum for each method kind
  - Moved parameter resolution to the end of the chain, right before
    invoking the method.
  - The enum is used for storage in DataProviders for easier access.
- ProviderInformation created as early as possible
This commit is contained in:
Rsl1122 2019-03-17 17:52:20 +02:00
parent c5b28fe3f9
commit f10c2352df
16 changed files with 479 additions and 385 deletions

View File

@ -1,3 +1,19 @@
/*
* 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.db.sql.tables;
/**

View File

@ -112,11 +112,6 @@ public class DataProviderExtractor {
return dataProviders;
}
private Optional<Class> extractParameterClass(Method method) {
Class<?>[] parameterTypes = method.getParameterTypes();
return parameterTypes.length == 1 ? Optional.of(parameterTypes[0]) : Optional.empty();
}
private void extractAllDataProviders() {
PluginInfo pluginInfo = extensionExtractor.getPluginInfo();
MethodAnnotations methodAnnotations = extensionExtractor.getMethodAnnotations();
@ -136,13 +131,12 @@ public class DataProviderExtractor {
T annotation = entry.getValue();
Optional<Conditional> conditional = Optional.ofNullable(conditions.get(method));
Optional<Tab> tab = Optional.ofNullable(tabs.get(method));
Optional<Class> parameterClass = extractParameterClass(method);
factory.placeToDataProviders(
dataProviders, method, annotation,
conditional.map(Conditional::value).orElse(null),
tab.map(Tab::value).orElse(null),
pluginInfo.name(), parameterClass
pluginInfo.name()
);
}
}
@ -155,7 +149,7 @@ public class DataProviderExtractor {
interface DataProviderFactory<T extends Annotation> {
void placeToDataProviders(
DataProviders dataProviders,
Method method, T annotation, String condition, String tab, String pluginName, Optional<Class> parameter
Method method, T annotation, String condition, String tab, String pluginName
);
}
}

View File

@ -0,0 +1,58 @@
/*
* 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;
import com.djrapitops.plan.extension.Group;
import java.lang.reflect.Method;
import java.util.UUID;
/**
* Utility enum for determining what kind of parameters a provider method used.
* <p>
* This also allows figuring out where to save method results.
*
* @author Rsl1122
*/
public enum MethodType {
PLAYER_UUID,
PLAYER_NAME,
GROUP,
SERVER;
public static MethodType forMethod(Method method) {
int parameterCount = method.getParameterCount();
if (parameterCount == 0) {
return SERVER;
}
Class<?>[] parameterTypes = method.getParameterTypes();
Class<?> firstParameter = parameterTypes[0];
if (UUID.class.equals(firstParameter)) {
return PLAYER_UUID;
} else if (String.class.equals(firstParameter)) {
return PLAYER_NAME;
} else if (Group.class.equals(firstParameter)) {
return GROUP;
}
throw new IllegalArgumentException(method.getDeclaringClass() + " method " + method.getName() + " had invalid parameters.");
}
}

View File

@ -0,0 +1,81 @@
/*
* 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;
import com.djrapitops.plan.extension.icon.Icon;
/**
* Represents the annotation information provided on a method.
*
* @author Rsl1122
*/
public class ProviderInformation {
private final String pluginName;
private final String name;
private final String text;
private final String description;
private final Icon icon;
private final int priority;
private final String tab; // can be null
private final String condition; // can be null
public ProviderInformation(
String pluginName, String name, String text, String description, Icon icon, int priority, String tab, String condition
) {
this.pluginName = pluginName;
this.name = name;
this.text = text;
this.description = description;
this.icon = icon;
this.priority = priority;
this.tab = tab;
this.condition = condition;
}
public String getPluginName() {
return pluginName;
}
public String getName() {
return name;
}
public String getText() {
return text;
}
public String getDescription() {
return description;
}
public Icon getIcon() {
return icon;
}
public int getPriority() {
return priority;
}
public String getTab() {
return tab;
}
public String getCondition() {
return condition;
}
}

View File

@ -19,14 +19,19 @@ package com.djrapitops.plan.extension.implementation;
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.storage.transactions.RemoveInvalidResultsTransaction;
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.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.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;
/**
@ -75,7 +80,39 @@ public class ProviderValueGatherer {
database.executeTransaction(new RemoveInvalidResultsTransaction(pluginName, serverUUID, extractor.getInvalidatedMethods()));
}
public void updateValues(UUID playerUUID) {
public void updateValues(UUID playerUUID, String playerName) {
gatherBooleanData(playerUUID, playerName);
}
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<>();
// 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));
}
}
}

View File

@ -16,13 +16,12 @@
*/
package com.djrapitops.plan.extension.implementation.providers;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.annotation.BooleanProvider;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a DataExtension API method annotated with {@link BooleanProvider} annotation.
@ -31,74 +30,28 @@ import java.util.UUID;
*
* @author Rsl1122
*/
public class BooleanDataProvider<T> extends DataProvider<T, Boolean> {
public class BooleanDataProvider extends DataProvider<Boolean> {
private final String providedCondition;
private BooleanDataProvider(
String plugin, String condition, String tab, int priority, Icon icon,
String text, String description, MethodWrapper<T, Boolean> method, String providedCondition
) {
super(plugin, condition, tab, priority, icon, text, description, method);
private BooleanDataProvider(ProviderInformation providerInformation, MethodWrapper<Boolean> method, String providedCondition) {
super(providerInformation, method);
this.providedCondition = providedCondition;
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, BooleanProvider annotation,
String condition, String tab, String pluginName, Optional<Class> parameterClass
String condition, String tab, String pluginName
) {
if (parameterClass.isPresent()) {
if (UUID.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
UUID.class, Boolean.class,
new BooleanDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, UUID.class, Boolean.class),
annotation.conditionName()
)
);
} else if (String.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
String.class, Boolean.class,
new BooleanDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, String.class, Boolean.class),
annotation.conditionName()
)
);
} else if (Group.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
Group.class, Boolean.class,
new BooleanDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, Group.class, Boolean.class),
annotation.conditionName()
)
);
}
} else {
dataProviders.put(
null, Boolean.class,
new BooleanDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, null, Boolean.class),
annotation.conditionName()
)
);
}
MethodWrapper<Boolean> methodWrapper = new MethodWrapper<>(method, Boolean.class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), tab, condition
);
dataProviders.put(new BooleanDataProvider(providerInformation, methodWrapper, annotation.conditionName()));
}
public Optional<String> getProvidedCondition() {

View File

@ -16,77 +16,28 @@
*/
package com.djrapitops.plan.extension.implementation.providers;
import com.djrapitops.plan.extension.icon.Icon;
import java.util.Optional;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
/**
* Abstract representation of all values a Provider annotation provides.
*
* @author Rsl1122
*/
public abstract class DataProvider<T, K> {
public abstract class DataProvider<T> {
private final String plugin;
private final String condition; // can be null
private final String tab; // can be null
private final int priority;
private final ProviderInformation providerInformation;
private final MethodWrapper<T> method;
private final Icon icon;
private final String text;
private final String description;
private final MethodWrapper<T, K> method;
public DataProvider(
String plugin,
String condition,
String tab,
int priority,
Icon icon,
String text,
String description,
MethodWrapper<T, K> method
) {
this.plugin = plugin;
this.condition = condition;
this.tab = tab;
this.priority = priority;
this.icon = icon;
this.text = text;
this.description = description;
public DataProvider(ProviderInformation providerInformation, MethodWrapper<T> method) {
this.providerInformation = providerInformation;
this.method = method;
}
public String getPlugin() {
return plugin;
}
public int getPriority() {
return priority;
}
public Icon getIcon() {
return icon;
}
public String getText() {
return text;
}
public String getDescription() {
return description;
}
public Optional<String> getCondition() {
return Optional.ofNullable(condition);
}
public Optional<String> getTab() {
return Optional.ofNullable(tab);
}
public MethodWrapper<T, K> getMethod() {
public MethodWrapper<T> getMethod() {
return method;
}
public ProviderInformation getProviderInformation() {
return providerInformation;
}
}

View File

@ -16,10 +16,9 @@
*/
package com.djrapitops.plan.extension.implementation.providers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.djrapitops.plan.extension.implementation.MethodType;
import java.util.*;
/**
* Group class for handling multiple different types of {@link DataProvider}s.
@ -28,23 +27,54 @@ import java.util.Map;
*/
public class DataProviders {
private Map<Class, Map<Class, List<DataProvider>>> byReturnType;
private Map<MethodType, Map<Class, List<DataProvider>>> byMethodType;
public DataProviders() {
byReturnType = new HashMap<>();
byMethodType = new EnumMap<>(MethodType.class);
}
public <T, K> void put(Class<T> parameterType, Class<K> returnType, DataProvider<T, K> provider) {
Map<Class, List<DataProvider>> byParameterType = byReturnType.getOrDefault(returnType, new HashMap<>());
List<DataProvider> dataProviders = byParameterType.getOrDefault(parameterType, new ArrayList<>());
public <T> void put(DataProvider<T> provider) {
MethodWrapper<T> method = provider.getMethod();
MethodType methodType = method.getMethodType();
Class<T> resultType = method.getResultType();
Map<Class, List<DataProvider>> byParameterType = byMethodType.getOrDefault(methodType, new HashMap<>());
List<DataProvider> dataProviders = byParameterType.getOrDefault(resultType, new ArrayList<>());
dataProviders.add(provider);
byParameterType.put(parameterType, dataProviders);
byReturnType.put(returnType, byParameterType);
byParameterType.put(resultType, dataProviders);
byMethodType.put(methodType, byParameterType);
}
public <T, K> List<DataProvider> get(Class<T> parameterType, Class<K> returnType) {
return byReturnType.getOrDefault(returnType, new HashMap<>()).getOrDefault(parameterType, new ArrayList<>());
public <T> List<DataProvider<T>> getPlayerMethodsByType(Class<T> returnType) {
Map<Class, List<DataProvider>> providersAcceptingUUID = byMethodType.getOrDefault(MethodType.PLAYER_UUID, new HashMap<>());
Map<Class, List<DataProvider>> providersAcceptingName = byMethodType.getOrDefault(MethodType.PLAYER_NAME, new HashMap<>());
List<DataProvider<T>> byReturnType = new ArrayList<>();
for (DataProvider dataProvider : providersAcceptingUUID.getOrDefault(returnType, Collections.emptyList())) {
byReturnType.add((DataProvider<T>) dataProvider);
}
for (DataProvider dataProvider : providersAcceptingName.getOrDefault(returnType, Collections.emptyList())) {
byReturnType.add((DataProvider<T>) dataProvider);
}
return byReturnType;
}
public <T> List<DataProvider<T>> getServerMethodsByType(Class<T> returnType) {
List<DataProvider<T>> byReturnType = new ArrayList<>();
for (DataProvider dataProvider : byMethodType.getOrDefault(MethodType.SERVER, new HashMap<>()).getOrDefault(returnType, Collections.emptyList())) {
byReturnType.add((DataProvider<T>) dataProvider);
}
return byReturnType;
}
public <T> List<DataProvider<T>> getGroupMethodsByType(Class<T> returnType) {
List<DataProvider<T>> byReturnType = new ArrayList<>();
for (DataProvider dataProvider : byMethodType.getOrDefault(MethodType.GROUP, new HashMap<>()).getOrDefault(returnType, Collections.emptyList())) {
byReturnType.add((DataProvider<T>) dataProvider);
}
return byReturnType;
}
}

View File

@ -16,13 +16,11 @@
*/
package com.djrapitops.plan.extension.implementation.providers;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.annotation.DoubleProvider;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a DataExtension API method annotated with {@link DoubleProvider} annotation.
@ -31,65 +29,23 @@ import java.util.UUID;
*
* @author Rsl1122
*/
public class DoubleDataProvider<T> extends DataProvider<T, Double> {
public class DoubleDataProvider extends DataProvider<Double> {
private DoubleDataProvider(
String plugin, String condition, String tab, int priority, Icon icon,
String text, String description, MethodWrapper<T, Double> method
) {
super(plugin, condition, tab, priority, icon, text, description, method);
private DoubleDataProvider(ProviderInformation providerInformation, MethodWrapper<Double> methodWrapper) {
super(providerInformation, methodWrapper);
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, DoubleProvider annotation,
String condition, String tab, String pluginName, Optional<Class> parameterClass
String condition, String tab, String pluginName
) {
if (parameterClass.isPresent()) {
if (UUID.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
UUID.class, Double.class,
new DoubleDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, UUID.class, Double.class)
)
);
} else if (String.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
String.class, Double.class,
new DoubleDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, String.class, Double.class)
)
);
} else if (Group.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
Group.class, Double.class,
new DoubleDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, Group.class, Double.class)
)
);
}
} else {
dataProviders.put(
null, Double.class,
new DoubleDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, null, Double.class)
)
);
}
MethodWrapper<Double> methodWrapper = new MethodWrapper<>(method, Double.class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), tab, condition
);
dataProviders.put(new DoubleDataProvider(providerInformation, methodWrapper));
}
}

View File

@ -17,38 +17,75 @@
package com.djrapitops.plan.extension.implementation.providers;
import com.djrapitops.plan.extension.DataExtension;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.implementation.MethodType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.UUID;
/**
* Wrap a Method so that it is easier to call.
*
* @author Rsl1122
*/
public class MethodWrapper<T, K> {
public class MethodWrapper<T> {
private final Method method;
private final Class<T> parameterType;
private final Class<K> resultType;
private final Class<T> resultType;
private MethodType methodType;
public MethodWrapper(Method method, Class<T> parameterType, Class<K> resultType) {
public MethodWrapper(Method method, Class<T> resultType) {
this.method = method;
this.parameterType = parameterType;
this.resultType = resultType;
methodType = MethodType.forMethod(this.method);
}
public K callMethod(DataExtension extension, T parameter) throws InvocationTargetException, IllegalAccessException {
if (parameterType == null) {
return resultType.cast(method.invoke(extension));
public T callMethod(DataExtension extension, UUID playerUUID, String playerName) throws InvocationTargetException, IllegalAccessException {
if (methodType != MethodType.PLAYER_NAME && methodType != MethodType.PLAYER_UUID) {
throw new IllegalStateException(method.getDeclaringClass() + " method " + method.getName() + " is not GROUP method.");
}
if (parameterType.isInstance(parameter)) {
return resultType.cast(method.invoke(extension, parameter));
return callMethod(extension, playerUUID, playerName, null);
}
public T callMethod(DataExtension extension, Group group) throws InvocationTargetException, IllegalAccessException {
if (methodType != MethodType.GROUP) {
throw new IllegalStateException(method.getDeclaringClass() + " method " + method.getName() + " is not GROUP method.");
}
return callMethod(extension, null, null, group);
}
public T callMethod(DataExtension extension) throws InvocationTargetException, IllegalAccessException {
if (methodType != MethodType.SERVER) {
throw new IllegalStateException(method.getDeclaringClass() + " method " + method.getName() + " is not SERVER method.");
}
return callMethod(extension, null, null, null);
}
public T callMethod(DataExtension extension, UUID playerUUID, String playerName, Group group) throws InvocationTargetException, IllegalAccessException {
switch (methodType) {
case SERVER:
return resultType.cast(method.invoke(extension));
case PLAYER_UUID:
return resultType.cast(method.invoke(extension, playerUUID));
case PLAYER_NAME:
return resultType.cast(method.invoke(extension, playerName));
case GROUP:
return resultType.cast(method.invoke(extension, group));
default:
throw new IllegalArgumentException(method.getDeclaringClass() + " method " + method.getName() + " had invalid parameters.");
}
throw new IllegalArgumentException(parameter.getClass().getName() + " can not be accepted as parameter when type is " + parameterType.getName());
}
public String getMethodName() {
return method.getName();
}
public MethodType getMethodType() {
return methodType;
}
public Class<T> getResultType() {
return resultType;
}
}

View File

@ -16,13 +16,11 @@
*/
package com.djrapitops.plan.extension.implementation.providers;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.annotation.NumberProvider;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a DataExtension API method annotated with {@link NumberProvider} annotation.
@ -31,65 +29,23 @@ import java.util.UUID;
*
* @author Rsl1122
*/
public class NumberDataProvider<T> extends DataProvider<T, Long> {
public class NumberDataProvider extends DataProvider<Long> {
private NumberDataProvider(
String plugin, String condition, String tab, int priority, Icon icon,
String text, String description, MethodWrapper<T, Long> method
) {
super(plugin, condition, tab, priority, icon, text, description, method);
private NumberDataProvider(ProviderInformation providerInformation, MethodWrapper<Long> methodWrapper) {
super(providerInformation, methodWrapper);
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, NumberProvider annotation,
String condition, String tab, String pluginName, Optional<Class> parameterClass
String condition, String tab, String pluginName
) {
if (parameterClass.isPresent()) {
if (UUID.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
UUID.class, Long.class,
new NumberDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, UUID.class, Long.class)
)
);
} else if (String.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
String.class, Long.class,
new NumberDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, String.class, Long.class)
)
);
} else if (Group.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
Group.class, Long.class,
new NumberDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, Group.class, Long.class)
)
);
}
} else {
dataProviders.put(
null, Long.class,
new NumberDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, null, Long.class)
)
);
}
MethodWrapper<Long> methodWrapper = new MethodWrapper<>(method, Long.class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), tab, condition
);
dataProviders.put(new NumberDataProvider(providerInformation, methodWrapper));
}
}

View File

@ -16,13 +16,11 @@
*/
package com.djrapitops.plan.extension.implementation.providers;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.annotation.PercentageProvider;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a DataExtension API method annotated with {@link PercentageProvider} annotation.
@ -31,65 +29,23 @@ import java.util.UUID;
*
* @author Rsl1122
*/
public class PercentageDataProvider<T> extends DataProvider<T, Double> {
public class PercentageDataProvider extends DataProvider<Double> {
private PercentageDataProvider(
String plugin, String condition, String tab, int priority, Icon icon,
String text, String description, MethodWrapper<T, Double> method
) {
super(plugin, condition, tab, priority, icon, text, description, method);
private PercentageDataProvider(ProviderInformation providerInformation, MethodWrapper<Double> methodWrapper) {
super(providerInformation, methodWrapper);
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, PercentageProvider annotation,
String condition, String tab, String pluginName, Optional<Class> parameterClass
String condition, String tab, String pluginName
) {
if (parameterClass.isPresent()) {
if (UUID.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
UUID.class, Double.class,
new PercentageDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, UUID.class, Double.class)
)
);
} else if (String.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
String.class, Double.class,
new PercentageDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, String.class, Double.class)
)
);
} else if (Group.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
Group.class, Double.class,
new PercentageDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, Group.class, Double.class)
)
);
}
} else {
dataProviders.put(
null, Double.class,
new PercentageDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, null, Double.class)
)
);
}
MethodWrapper<Double> methodWrapper = new MethodWrapper<>(method, Double.class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), tab, condition
);
dataProviders.put(new PercentageDataProvider(providerInformation, methodWrapper));
}
}

View File

@ -16,13 +16,11 @@
*/
package com.djrapitops.plan.extension.implementation.providers;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.annotation.StringProvider;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a DataExtension API method annotated with {@link StringProvider} annotation.
@ -31,65 +29,23 @@ import java.util.UUID;
*
* @author Rsl1122
*/
public class StringDataProvider<T> extends DataProvider<T, String> {
public class StringDataProvider extends DataProvider<String> {
private StringDataProvider(
String plugin, String condition, String tab, int priority, Icon icon,
String text, String description, MethodWrapper<T, String> method
) {
super(plugin, condition, tab, priority, icon, text, description, method);
private StringDataProvider(ProviderInformation providerInformation, MethodWrapper<String> methodWrapper) {
super(providerInformation, methodWrapper);
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, StringProvider annotation,
String condition, String tab, String pluginName, Optional<Class> parameterClass
String condition, String tab, String pluginName
) {
if (parameterClass.isPresent()) {
if (UUID.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
UUID.class, String.class,
new StringDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, UUID.class, String.class)
)
);
} else if (String.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
String.class, String.class,
new StringDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, String.class, String.class)
)
);
} else if (Group.class.isAssignableFrom(parameterClass.get())) {
dataProviders.put(
Group.class, String.class,
new StringDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, Group.class, String.class)
)
);
}
} else {
dataProviders.put(
null, String.class,
new StringDataProvider<>(
pluginName, condition, tab,
annotation.priority(),
new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor()),
annotation.text(), annotation.description(),
new MethodWrapper<>(method, null, String.class)
)
);
}
MethodWrapper<String> methodWrapper = new MethodWrapper<>(method, String.class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), tab, condition
);
dataProviders.put(new StringDataProvider(providerInformation, methodWrapper));
}
}

View File

@ -0,0 +1,48 @@
/*
* 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;
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 com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider}.
*
* @author Rsl1122
*/
public class StoreBooleanProviderTransaction extends Transaction {
private final DataProvider<Boolean> booleanProvider;
private final String providedCondition;
private final UUID serverUUID;
public StoreBooleanProviderTransaction(DataProvider<Boolean> booleanProvider, String providedCondition, UUID serverUUID) {
this.booleanProvider = booleanProvider;
this.providedCondition = providedCondition;
this.serverUUID = serverUUID;
}
@Override
protected void performOperations() {
ProviderInformation providerInformation = booleanProvider.getProviderInformation();
// TODO Store provider in a table
}
}

View File

@ -1,3 +1,19 @@
/*
* 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;
import com.djrapitops.plan.db.access.ExecStatement;

View File

@ -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
*
* @author Rsl1122
*/
public class StorePlayerBooleanResultTransaction extends Transaction {
private final String pluginName;
private final UUID serverUUID;
private final String methodName;
private final UUID playerUUID;
private final boolean value;
public StorePlayerBooleanResultTransaction(String pluginName, UUID serverUUID, String methodName, UUID playerUUID, boolean 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
}
}