Provider Extraction + priority to Providers:

Implemented methods for extracting each kind of Provider annotation
related method information to a DataProvider.

DataProviders required some duplicate code due to type erasure of the
parameter class.

----

Added Display-priority to Providers, highest value is placed top most.

InvalidateMethod annotations are now extracted.
This commit is contained in:
Rsl1122 2019-03-14 16:53:05 +02:00
parent 305d0fd77c
commit b52d113e2e
14 changed files with 647 additions and 13 deletions

View File

@ -53,6 +53,15 @@ public @interface BooleanProvider {
*/ */
String text(); String text();
/**
* Display-priority of the value, highest value is placed top most.
* <p>
* Two values with same priority may appear in a random order.
*
* @return Priority between 0 and {@code Integer.MAX_VALUE}.
*/
int priority() default 0;
/** /**
* Text displayed when hovering over the value, limited to 150 characters. * Text displayed when hovering over the value, limited to 150 characters.
* <p> * <p>
@ -96,5 +105,4 @@ public @interface BooleanProvider {
* @return Preferred color. If none are specified defaults are used. * @return Preferred color. If none are specified defaults are used.
*/ */
Color iconColor() default Color.NONE; Color iconColor() default Color.NONE;
}
}

View File

@ -45,6 +45,15 @@ public @interface DoubleProvider {
*/ */
String text(); String text();
/**
* Display-priority of the value, highest value is placed top most.
* <p>
* Two values with same priority may appear in a random order.
*
* @return Priority between 0 and {@code Integer.MAX_VALUE}.
*/
int priority() default 0;
/** /**
* Text displayed when hovering over the value, limited to 150 characters. * Text displayed when hovering over the value, limited to 150 characters.
* <p> * <p>

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.annotation; package com.djrapitops.plan.extension.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;

View File

@ -49,6 +49,15 @@ public @interface NumberProvider {
*/ */
String text(); String text();
/**
* Display-priority of the value, highest value is placed top most.
* <p>
* Two values with same priority may appear in a random order.
*
* @return Priority between 0 and {@code Integer.MAX_VALUE}.
*/
int priority() default 0;
/** /**
* Text displayed when hovering over the value, limited to 150 characters. * Text displayed when hovering over the value, limited to 150 characters.
* <p> * <p>

View File

@ -48,6 +48,15 @@ public @interface PercentageProvider {
*/ */
String text(); String text();
/**
* Display-priority of the value, highest value is placed top most.
* <p>
* Two values with same priority may appear in a random order.
*
* @return Priority between 0 and {@code Integer.MAX_VALUE}.
*/
int priority() default 0;
/** /**
* Text displayed when hovering over the value, limited to 150 characters. * Text displayed when hovering over the value, limited to 150 characters.
* <p> * <p>

View File

@ -50,6 +50,15 @@ public @interface StringProvider {
*/ */
String text(); String text();
/**
* Display-priority of the value, highest value is placed top most.
* <p>
* Two values with same priority may appear in a random order.
*
* @return Priority between 0 and {@code Integer.MAX_VALUE}.
*/
int priority() default 0;
/** /**
* Text displayed when hovering over the value, limited to 150 characters. * Text displayed when hovering over the value, limited to 150 characters.
* <p> * <p>

View File

@ -44,6 +44,7 @@ public final class ExtensionExtractor {
private PluginInfo pluginInfo; private PluginInfo pluginInfo;
private TabOrder tabOrder; private TabOrder tabOrder;
private List<TabInfo> tabInformation; private List<TabInfo> tabInformation;
private List<InvalidateMethod> invalidMethods;
private MethodAnnotations methodAnnotations; private MethodAnnotations methodAnnotations;
public ExtensionExtractor(DataExtension extension) { public ExtensionExtractor(DataExtension extension) {
@ -74,6 +75,7 @@ public final class ExtensionExtractor {
public void extractAnnotationInformation() { public void extractAnnotationInformation() {
extractPluginInfo(); extractPluginInfo();
extractInvalidMethods();
extractMethodAnnotations(); extractMethodAnnotations();
validateMethodAnnotations(); validateMethodAnnotations();
@ -310,6 +312,22 @@ public final class ExtensionExtractor {
} }
} }
private void extractInvalidMethods() {
invalidMethods = new ArrayList<>();
getClassAnnotation(InvalidateMethod.Multiple.class).ifPresent(tabs -> {
for (InvalidateMethod tabInfo : tabs.value()) {
String methodName = tabInfo.value();
// Length restriction check
if (methodName.length() > 50) {
warnings.add(extensionName + " invalidated method '" + methodName + "' was over 50 characters.");
}
invalidMethods.add(tabInfo);
}
});
}
public List<String> getWarnings() { public List<String> getWarnings() {
return warnings; return warnings;
} }
@ -323,10 +341,14 @@ public final class ExtensionExtractor {
} }
public List<TabInfo> getTabInformation() { public List<TabInfo> getTabInformation() {
return tabInformation; return tabInformation != null ? tabInformation : Collections.emptyList();
} }
public MethodAnnotations getMethodAnnotations() { public MethodAnnotations getMethodAnnotations() {
return methodAnnotations; return methodAnnotations;
} }
public List<InvalidateMethod> getInvalidateMethodAnnotations() {
return invalidMethods != null ? invalidMethods : Collections.emptyList();
}
} }

View File

@ -17,14 +17,15 @@
package com.djrapitops.plan.extension.implementation; package com.djrapitops.plan.extension.implementation;
import com.djrapitops.plan.extension.DataExtension; import com.djrapitops.plan.extension.DataExtension;
import com.djrapitops.plan.extension.annotation.PluginInfo; import com.djrapitops.plan.extension.annotation.*;
import com.djrapitops.plan.extension.annotation.Tab;
import com.djrapitops.plan.extension.annotation.TabInfo;
import com.djrapitops.plan.extension.annotation.TabOrder;
import com.djrapitops.plan.extension.extractor.ExtensionExtractor; import com.djrapitops.plan.extension.extractor.ExtensionExtractor;
import com.djrapitops.plan.extension.extractor.MethodAnnotations;
import com.djrapitops.plan.extension.icon.Color; import com.djrapitops.plan.extension.icon.Color;
import com.djrapitops.plan.extension.icon.Icon; import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.providers.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -40,8 +41,8 @@ import java.util.stream.Collectors;
*/ */
public class DataProviderExtractor { public class DataProviderExtractor {
private final DataExtension extension;
private ExtensionExtractor extensionExtractor; private ExtensionExtractor extensionExtractor;
private DataProviders dataProviders;
/** /**
* Create a DataProviderExtractor. * Create a DataProviderExtractor.
@ -50,7 +51,6 @@ public class DataProviderExtractor {
* @throws IllegalArgumentException If something is badly wrong with the specified extension class annotations. * @throws IllegalArgumentException If something is badly wrong with the specified extension class annotations.
*/ */
public DataProviderExtractor(DataExtension extension) { public DataProviderExtractor(DataExtension extension) {
this.extension = extension;
extensionExtractor = new ExtensionExtractor(extension); extensionExtractor = new ExtensionExtractor(extension);
extensionExtractor.extractAnnotationInformation(); extensionExtractor.extractAnnotationInformation();
@ -85,4 +85,61 @@ public class DataProviderExtractor {
public Optional<String[]> getTabOrder() { public Optional<String[]> getTabOrder() {
return extensionExtractor.getTabOrder().map(TabOrder::value); return extensionExtractor.getTabOrder().map(TabOrder::value);
} }
public Collection<String> getInvalidatedMethods() {
return extensionExtractor.getInvalidateMethodAnnotations().stream()
.map(InvalidateMethod::value)
.collect(Collectors.toSet());
}
private Optional<Class> extractParameterClass(Method method) {
Class<?>[] parameterTypes = method.getParameterTypes();
return parameterTypes.length == 1 ? Optional.of(parameterTypes[0]) : Optional.empty();
}
public DataProviders getDataProviders() {
dataProviders = new DataProviders();
PluginInfo pluginInfo = extensionExtractor.getPluginInfo();
MethodAnnotations methodAnnotations = extensionExtractor.getMethodAnnotations();
Map<Method, Tab> tabs = methodAnnotations.getMethodAnnotations(Tab.class);
Map<Method, Conditional> conditions = methodAnnotations.getMethodAnnotations(Conditional.class);
extractDataProviders(pluginInfo, tabs, conditions, BooleanProvider.class, BooleanDataProvider::placeToDataProviders);
extractDataProviders(pluginInfo, tabs, conditions, DoubleProvider.class, DoubleDataProvider::placeToDataProviders);
extractDataProviders(pluginInfo, tabs, conditions, PercentageProvider.class, PercentageDataProvider::placeToDataProviders);
extractDataProviders(pluginInfo, tabs, conditions, NumberProvider.class, NumberDataProvider::placeToDataProviders);
extractDataProviders(pluginInfo, tabs, conditions, StringProvider.class, StringDataProvider::placeToDataProviders);
return dataProviders;
}
private <T extends Annotation> void extractDataProviders(PluginInfo pluginInfo, Map<Method, Tab> tabs, Map<Method, Conditional> conditions, Class<T> ofKind, DataProviderFactory<T> factory) {
for (Map.Entry<Method, T> entry : extensionExtractor.getMethodAnnotations().getMethodAnnotations(ofKind).entrySet()) {
Method method = entry.getKey();
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
);
}
}
/**
* Functional interface for defining a method that places required DataProvider to DataProviders.
*
* @param <T> Type of the annotation on the method that is going to be extracted.
*/
interface DataProviderFactory<T extends Annotation> {
void placeToDataProviders(
DataProviders dataProviders,
Method method, T annotation, String condition, String tab, String pluginName, Optional<Class> parameter
);
}
} }

View File

@ -0,0 +1,107 @@
/*
* 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;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.annotation.BooleanProvider;
import com.djrapitops.plan.extension.icon.Icon;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a DataExtension API method annotated with {@link BooleanProvider} annotation.
* <p>
* Used to obtain data to place in the database.
*
* @author Rsl1122
*/
public class BooleanDataProvider<T> extends DataProvider<T, 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);
this.providedCondition = providedCondition;
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, BooleanProvider annotation,
String condition, String tab, String pluginName, Optional<Class> parameterClass
) {
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()
)
);
}
}
public Optional<String> getProvidedCondition() {
return Optional.ofNullable(providedCondition);
}
}

View File

@ -0,0 +1,95 @@
/*
* 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;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.annotation.DoubleProvider;
import com.djrapitops.plan.extension.icon.Icon;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a DataExtension API method annotated with {@link DoubleProvider} annotation.
* <p>
* Used to obtain data to place in the database.
*
* @author Rsl1122
*/
public class DoubleDataProvider<T> extends DataProvider<T, 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);
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, DoubleProvider annotation,
String condition, String tab, String pluginName, Optional<Class> parameterClass
) {
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)
)
);
}
}
}

View File

@ -29,15 +29,23 @@ import java.lang.reflect.Method;
public class MethodWrapper<T, K> { public class MethodWrapper<T, K> {
private final Method method; private final Method method;
private final Class<K> result; private final Class<T> parameterType;
private final Class<K> resultType;
public MethodWrapper(Method method, Class<T> parameter, Class<K> result) { public MethodWrapper(Method method, Class<T> parameterType, Class<K> resultType) {
this.method = method; this.method = method;
this.result = result; this.parameterType = parameterType;
this.resultType = resultType;
} }
public K callMethod(DataExtension extension, T parameter) throws InvocationTargetException, IllegalAccessException { public K callMethod(DataExtension extension, T parameter) throws InvocationTargetException, IllegalAccessException {
return result.cast(method.invoke(extension, parameter)); if (parameterType == null) {
return resultType.cast(method.invoke(extension));
}
if (parameterType.isInstance(parameter)) {
return resultType.cast(method.invoke(extension, parameter));
}
throw new IllegalArgumentException(parameter.getClass().getName() + " can not be accepted as parameter when type is " + parameterType.getName());
} }
public String getMethodName() { public String getMethodName() {

View File

@ -0,0 +1,95 @@
/*
* 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;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.annotation.NumberProvider;
import com.djrapitops.plan.extension.icon.Icon;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a DataExtension API method annotated with {@link NumberProvider} annotation.
* <p>
* Used to obtain data to place in the database.
*
* @author Rsl1122
*/
public class NumberDataProvider<T> extends DataProvider<T, 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);
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, NumberProvider annotation,
String condition, String tab, String pluginName, Optional<Class> parameterClass
) {
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)
)
);
}
}
}

View File

@ -0,0 +1,95 @@
/*
* 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;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.annotation.PercentageProvider;
import com.djrapitops.plan.extension.icon.Icon;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a DataExtension API method annotated with {@link PercentageProvider} annotation.
* <p>
* Used to obtain data to place in the database.
*
* @author Rsl1122
*/
public class PercentageDataProvider<T> extends DataProvider<T, 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);
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, PercentageProvider annotation,
String condition, String tab, String pluginName, Optional<Class> parameterClass
) {
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)
)
);
}
}
}

View File

@ -0,0 +1,95 @@
/*
* 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;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.annotation.StringProvider;
import com.djrapitops.plan.extension.icon.Icon;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
/**
* Represents a DataExtension API method annotated with {@link StringProvider} annotation.
* <p>
* Used to obtain data to place in the database.
*
* @author Rsl1122
*/
public class StringDataProvider<T> extends DataProvider<T, 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);
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, StringProvider annotation,
String condition, String tab, String pluginName, Optional<Class> parameterClass
) {
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)
)
);
}
}
}