From b52d113e2e20cb129eed1a361197e6a568815fbb Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 14 Mar 2019 16:53:05 +0200 Subject: [PATCH] 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. --- .../extension/annotation/BooleanProvider.java | 12 +- .../extension/annotation/DoubleProvider.java | 9 ++ .../annotation/InvalidateMethod.java | 16 +++ .../extension/annotation/NumberProvider.java | 9 ++ .../annotation/PercentageProvider.java | 9 ++ .../extension/annotation/StringProvider.java | 9 ++ .../extractor/ExtensionExtractor.java | 24 +++- .../implementation/DataProviderExtractor.java | 69 ++++++++++- .../providers/BooleanDataProvider.java | 107 ++++++++++++++++++ .../providers/DoubleDataProvider.java | 95 ++++++++++++++++ .../providers/MethodWrapper.java | 16 ++- .../providers/NumberDataProvider.java | 95 ++++++++++++++++ .../providers/PercentageDataProvider.java | 95 ++++++++++++++++ .../providers/StringDataProvider.java | 95 ++++++++++++++++ 14 files changed, 647 insertions(+), 13 deletions(-) create mode 100644 Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/BooleanDataProvider.java create mode 100644 Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/DoubleDataProvider.java create mode 100644 Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/NumberDataProvider.java create mode 100644 Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/PercentageDataProvider.java create mode 100644 Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/StringDataProvider.java diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/BooleanProvider.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/BooleanProvider.java index 9127f9148..bf51f941b 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/BooleanProvider.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/BooleanProvider.java @@ -53,6 +53,15 @@ public @interface BooleanProvider { */ String text(); + /** + * Display-priority of the value, highest value is placed top most. + *

+ * 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. *

@@ -96,5 +105,4 @@ public @interface BooleanProvider { * @return Preferred color. If none are specified defaults are used. */ Color iconColor() default Color.NONE; - -} +} \ No newline at end of file diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/DoubleProvider.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/DoubleProvider.java index b809337a9..67bf15a19 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/DoubleProvider.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/DoubleProvider.java @@ -45,6 +45,15 @@ public @interface DoubleProvider { */ String text(); + /** + * Display-priority of the value, highest value is placed top most. + *

+ * 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. *

diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/InvalidateMethod.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/InvalidateMethod.java index 6cd3cc73c..ca10a9f42 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/InvalidateMethod.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/InvalidateMethod.java @@ -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 . + */ package com.djrapitops.plan.extension.annotation; import java.lang.annotation.*; diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/NumberProvider.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/NumberProvider.java index 4253d8ce4..1f62026e1 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/NumberProvider.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/NumberProvider.java @@ -49,6 +49,15 @@ public @interface NumberProvider { */ String text(); + /** + * Display-priority of the value, highest value is placed top most. + *

+ * 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. *

diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/PercentageProvider.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/PercentageProvider.java index f7dff8502..fcf027c27 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/PercentageProvider.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/PercentageProvider.java @@ -48,6 +48,15 @@ public @interface PercentageProvider { */ String text(); + /** + * Display-priority of the value, highest value is placed top most. + *

+ * 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. *

diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/StringProvider.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/StringProvider.java index 691ed7744..13ecc481e 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/StringProvider.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/StringProvider.java @@ -50,6 +50,15 @@ public @interface StringProvider { */ String text(); + /** + * Display-priority of the value, highest value is placed top most. + *

+ * 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. *

diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java index 700a22308..1b5a0bae2 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java @@ -44,6 +44,7 @@ public final class ExtensionExtractor { private PluginInfo pluginInfo; private TabOrder tabOrder; private List tabInformation; + private List invalidMethods; private MethodAnnotations methodAnnotations; public ExtensionExtractor(DataExtension extension) { @@ -74,6 +75,7 @@ public final class ExtensionExtractor { public void extractAnnotationInformation() { extractPluginInfo(); + extractInvalidMethods(); extractMethodAnnotations(); 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 getWarnings() { return warnings; } @@ -323,10 +341,14 @@ public final class ExtensionExtractor { } public List getTabInformation() { - return tabInformation; + return tabInformation != null ? tabInformation : Collections.emptyList(); } public MethodAnnotations getMethodAnnotations() { return methodAnnotations; } + + public List getInvalidateMethodAnnotations() { + return invalidMethods != null ? invalidMethods : Collections.emptyList(); + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/DataProviderExtractor.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/DataProviderExtractor.java index b9c90a247..b44433c2f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/DataProviderExtractor.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/DataProviderExtractor.java @@ -17,14 +17,15 @@ package com.djrapitops.plan.extension.implementation; import com.djrapitops.plan.extension.DataExtension; -import com.djrapitops.plan.extension.annotation.PluginInfo; -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.annotation.*; 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.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.Map; import java.util.Optional; @@ -40,8 +41,8 @@ import java.util.stream.Collectors; */ public class DataProviderExtractor { - private final DataExtension extension; private ExtensionExtractor extensionExtractor; + private DataProviders dataProviders; /** * Create a DataProviderExtractor. @@ -50,7 +51,6 @@ public class DataProviderExtractor { * @throws IllegalArgumentException If something is badly wrong with the specified extension class annotations. */ public DataProviderExtractor(DataExtension extension) { - this.extension = extension; extensionExtractor = new ExtensionExtractor(extension); extensionExtractor.extractAnnotationInformation(); @@ -85,4 +85,61 @@ public class DataProviderExtractor { public Optional getTabOrder() { return extensionExtractor.getTabOrder().map(TabOrder::value); } + + public Collection getInvalidatedMethods() { + return extensionExtractor.getInvalidateMethodAnnotations().stream() + .map(InvalidateMethod::value) + .collect(Collectors.toSet()); + } + + private Optional 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 tabs = methodAnnotations.getMethodAnnotations(Tab.class); + Map 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 void extractDataProviders(PluginInfo pluginInfo, Map tabs, Map conditions, Class ofKind, DataProviderFactory factory) { + for (Map.Entry entry : extensionExtractor.getMethodAnnotations().getMethodAnnotations(ofKind).entrySet()) { + Method method = entry.getKey(); + T annotation = entry.getValue(); + Optional conditional = Optional.ofNullable(conditions.get(method)); + Optional tab = Optional.ofNullable(tabs.get(method)); + Optional 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 Type of the annotation on the method that is going to be extracted. + */ + interface DataProviderFactory { + void placeToDataProviders( + DataProviders dataProviders, + Method method, T annotation, String condition, String tab, String pluginName, Optional parameter + ); + } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/BooleanDataProvider.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/BooleanDataProvider.java new file mode 100644 index 000000000..5372848a2 --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/BooleanDataProvider.java @@ -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 . + */ +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. + *

+ * Used to obtain data to place in the database. + * + * @author Rsl1122 + */ +public class BooleanDataProvider extends DataProvider { + + private final String providedCondition; + + private BooleanDataProvider( + String plugin, String condition, String tab, int priority, Icon icon, + String text, String description, MethodWrapper 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 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 getProvidedCondition() { + return Optional.ofNullable(providedCondition); + } +} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/DoubleDataProvider.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/DoubleDataProvider.java new file mode 100644 index 000000000..dbeb87d34 --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/DoubleDataProvider.java @@ -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 . + */ +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. + *

+ * Used to obtain data to place in the database. + * + * @author Rsl1122 + */ +public class DoubleDataProvider extends DataProvider { + + private DoubleDataProvider( + String plugin, String condition, String tab, int priority, Icon icon, + String text, String description, MethodWrapper 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 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) + ) + ); + } + } +} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java index b6759dd4f..3999111f9 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/MethodWrapper.java @@ -29,15 +29,23 @@ import java.lang.reflect.Method; public class MethodWrapper { private final Method method; - private final Class result; + private final Class parameterType; + private final Class resultType; - public MethodWrapper(Method method, Class parameter, Class result) { + public MethodWrapper(Method method, Class parameterType, Class resultType) { this.method = method; - this.result = result; + this.parameterType = parameterType; + this.resultType = resultType; } 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() { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/NumberDataProvider.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/NumberDataProvider.java new file mode 100644 index 000000000..f285663fd --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/NumberDataProvider.java @@ -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 . + */ +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. + *

+ * Used to obtain data to place in the database. + * + * @author Rsl1122 + */ +public class NumberDataProvider extends DataProvider { + + private NumberDataProvider( + String plugin, String condition, String tab, int priority, Icon icon, + String text, String description, MethodWrapper 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 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) + ) + ); + } + } +} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/PercentageDataProvider.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/PercentageDataProvider.java new file mode 100644 index 000000000..27823d2df --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/PercentageDataProvider.java @@ -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 . + */ +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. + *

+ * Used to obtain data to place in the database. + * + * @author Rsl1122 + */ +public class PercentageDataProvider extends DataProvider { + + private PercentageDataProvider( + String plugin, String condition, String tab, int priority, Icon icon, + String text, String description, MethodWrapper 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 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) + ) + ); + } + } +} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/StringDataProvider.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/StringDataProvider.java new file mode 100644 index 000000000..e668c619f --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/StringDataProvider.java @@ -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 . + */ +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. + *

+ * Used to obtain data to place in the database. + * + * @author Rsl1122 + */ +public class StringDataProvider extends DataProvider { + + private StringDataProvider( + String plugin, String condition, String tab, int priority, Icon icon, + String text, String description, MethodWrapper 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 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) + ) + ); + } + } +} \ No newline at end of file