From 6cbf28ad17961fbd932857c14c211d1be5e149d6 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 27 Aug 2019 13:01:12 +0300 Subject: [PATCH] Plan API 5.0-R0.2: Changed GroupProvider to return String[] --- Plan/api/build.gradle | 2 +- .../plan/extension/annotation/GroupProvider.java | 4 ++-- .../extension/extractor/ExtensionExtractor.java | 2 +- .../extension/extractor/ExtensionExtractorTest.java | 4 ++-- .../implementation/providers/GroupDataProvider.java | 7 +++---- .../gathering/GroupProviderValueGatherer.java | 9 ++++----- .../providers/StoreGroupProviderTransaction.java | 3 +-- .../results/StorePlayerGroupsResultTransaction.java | 9 ++++----- .../java/com/djrapitops/plan/db/DatabaseTest.java | 13 ++++++++----- 9 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Plan/api/build.gradle b/Plan/api/build.gradle index 87666faba..f3808b767 100644 --- a/Plan/api/build.gradle +++ b/Plan/api/build.gradle @@ -2,7 +2,7 @@ plugins { id "com.jfrog.bintray" version "1.8.4" } -ext.apiVersion = '5.0-R0.1' +ext.apiVersion = '5.0-R0.2' bintray { user = System.getenv('BINTRAY_USER') diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/GroupProvider.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/GroupProvider.java index 0f187e90a..83b319cd7 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/GroupProvider.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/annotation/GroupProvider.java @@ -25,12 +25,12 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Method annotation to provide {@code Group[]} array about a Player. + * Method annotation to provide {@code String[]} array of Group names about a Player. *

* This method annotation only works when used with {@code UUID} or {@code String} as a method parameter (for Players). *

* For example: - * {@code @GroupProvider public Group[] getJobs(UUID playerUUID) {}} + * {@code @GroupProvider public String[] getJobs(UUID playerUUID) {}} *

* Group data is parsed as Table for /server & /network page and similar to {@link StringProvider} for /player page. *

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 ee87624f2..a501ab834 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 @@ -278,7 +278,7 @@ public final class ExtensionExtractor { Method method = groupProvider.getKey(); GroupProvider annotation = groupProvider.getValue(); - validateReturnType(method, Group[].class); + validateReturnType(method, String[].class); validateMethodAnnotationPropertyLength(annotation.text(), "text", 50, method); validateMethodArguments(method, true, UUID.class, String.class); } diff --git a/Plan/api/src/test/java/com/djrapitops/plan/extension/extractor/ExtensionExtractorTest.java b/Plan/api/src/test/java/com/djrapitops/plan/extension/extractor/ExtensionExtractorTest.java index 1f01ab45f..74c036ba9 100644 --- a/Plan/api/src/test/java/com/djrapitops/plan/extension/extractor/ExtensionExtractorTest.java +++ b/Plan/api/src/test/java/com/djrapitops/plan/extension/extractor/ExtensionExtractorTest.java @@ -192,7 +192,7 @@ class ExtensionExtractorTest { } ExtensionExtractor underTest = new ExtensionExtractor(new Extension()); - assertEquals("Extension.method has invalid return type. was: java.lang.Double, expected: [Lcom.djrapitops.plan.extension.Group; (an array)", assertThrows(IllegalArgumentException.class, underTest::validateAnnotations).getMessage()); + assertEquals("Extension.method has invalid return type. was: java.lang.Double, expected: [Ljava.lang.String; (an array)", assertThrows(IllegalArgumentException.class, underTest::validateAnnotations).getMessage()); } @Test @@ -206,7 +206,7 @@ class ExtensionExtractorTest { } ExtensionExtractor underTest = new ExtensionExtractor(new Extension()); - assertEquals("Extension.method has invalid return type. was: com.djrapitops.plan.extension.Group, expected: [Lcom.djrapitops.plan.extension.Group; (an array)", assertThrows(IllegalArgumentException.class, underTest::validateAnnotations).getMessage()); + assertEquals("Extension.method has invalid return type. was: com.djrapitops.plan.extension.Group, expected: [Ljava.lang.String; (an array)", assertThrows(IllegalArgumentException.class, underTest::validateAnnotations).getMessage()); } @Test diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/GroupDataProvider.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/GroupDataProvider.java index eee44da69..962e9d6d8 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/GroupDataProvider.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/GroupDataProvider.java @@ -16,7 +16,6 @@ */ package com.djrapitops.plan.extension.implementation.providers; -import com.djrapitops.plan.extension.Group; import com.djrapitops.plan.extension.annotation.Conditional; import com.djrapitops.plan.extension.annotation.GroupProvider; import com.djrapitops.plan.extension.annotation.StringProvider; @@ -32,9 +31,9 @@ import java.lang.reflect.Method; * * @author Rsl1122 */ -public class GroupDataProvider extends DataProvider { +public class GroupDataProvider extends DataProvider { - private GroupDataProvider(ProviderInformation providerInformation, MethodWrapper methodWrapper) { + private GroupDataProvider(ProviderInformation providerInformation, MethodWrapper methodWrapper) { super(providerInformation, methodWrapper); } @@ -42,7 +41,7 @@ public class GroupDataProvider extends DataProvider { DataProviders dataProviders, Method method, GroupProvider annotation, Conditional condition, String tab, String pluginName ) { - MethodWrapper methodWrapper = new MethodWrapper<>(method, Group[].class); + MethodWrapper methodWrapper = new MethodWrapper<>(method, String[].class); Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.groupColor()); ProviderInformation providerInformation = new ProviderInformation( diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/GroupProviderValueGatherer.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/GroupProviderValueGatherer.java index b2ab4bc2d..a08c2b7b1 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/GroupProviderValueGatherer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/providers/gathering/GroupProviderValueGatherer.java @@ -19,7 +19,6 @@ package com.djrapitops.plan.extension.implementation.providers.gathering; import com.djrapitops.plan.api.exceptions.DataExtensionMethodCallException; import com.djrapitops.plan.db.Database; import com.djrapitops.plan.extension.DataExtension; -import com.djrapitops.plan.extension.Group; import com.djrapitops.plan.extension.implementation.ProviderInformation; import com.djrapitops.plan.extension.implementation.providers.DataProvider; import com.djrapitops.plan.extension.implementation.providers.DataProviders; @@ -58,7 +57,7 @@ class GroupProviderValueGatherer { } void gatherGroupDataOfPlayer(UUID playerUUID, String playerName, Conditions conditions) { - for (DataProvider groupProvider : dataProviders.getPlayerMethodsByType(Group[].class)) { + for (DataProvider groupProvider : dataProviders.getPlayerMethodsByType(String[].class)) { gatherGroupDataOfProvider(playerUUID, playerName, conditions, groupProvider); } } @@ -66,7 +65,7 @@ class GroupProviderValueGatherer { private void gatherGroupDataOfProvider( UUID playerUUID, String playerName, Conditions conditions, - DataProvider groupProvider + DataProvider groupProvider ) { ProviderInformation providerInformation = groupProvider.getProviderInformation(); Optional condition = providerInformation.getCondition(); @@ -74,9 +73,9 @@ class GroupProviderValueGatherer { return; } - MethodWrapper method = groupProvider.getMethod(); + MethodWrapper method = groupProvider.getMethod(); try { - Group[] result = method.callMethod(extension, playerUUID, playerName); + String[] result = method.callMethod(extension, playerUUID, playerName); if (result == null) { return; // Error during call } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/providers/StoreGroupProviderTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/providers/StoreGroupProviderTransaction.java index 9def72001..b9a245f2e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/providers/StoreGroupProviderTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/providers/StoreGroupProviderTransaction.java @@ -22,7 +22,6 @@ import com.djrapitops.plan.db.access.transactions.Transaction; import com.djrapitops.plan.db.sql.tables.ExtensionIconTable; import com.djrapitops.plan.db.sql.tables.ExtensionPluginTable; import com.djrapitops.plan.db.sql.tables.ExtensionTabTable; -import com.djrapitops.plan.extension.Group; import com.djrapitops.plan.extension.implementation.ProviderInformation; import com.djrapitops.plan.extension.implementation.providers.DataProvider; @@ -46,7 +45,7 @@ public class StoreGroupProviderTransaction extends Transaction { private final UUID serverUUID; private ProviderInformation providerInformation; - public StoreGroupProviderTransaction(DataProvider provider, UUID serverUUID) { + public StoreGroupProviderTransaction(DataProvider provider, UUID serverUUID) { this.serverUUID = serverUUID; providerInformation = provider.getProviderInformation(); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerGroupsResultTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerGroupsResultTransaction.java index 9f47b4d8b..3ae7dc1ef 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerGroupsResultTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerGroupsResultTransaction.java @@ -21,7 +21,6 @@ import com.djrapitops.plan.db.access.Executable; import com.djrapitops.plan.db.access.transactions.Transaction; import com.djrapitops.plan.db.sql.tables.ExtensionGroupsTable; import com.djrapitops.plan.db.sql.tables.ExtensionProviderTable; -import com.djrapitops.plan.extension.Group; import org.apache.commons.lang3.StringUtils; import java.sql.PreparedStatement; @@ -43,9 +42,9 @@ public class StorePlayerGroupsResultTransaction extends Transaction { private final String providerName; private final UUID playerUUID; - private final Group[] value; + private final String[] value; - public StorePlayerGroupsResultTransaction(String pluginName, UUID serverUUID, String providerName, UUID playerUUID, Group[] value) { + public StorePlayerGroupsResultTransaction(String pluginName, UUID serverUUID, String providerName, UUID playerUUID, String[] value) { this.pluginName = pluginName; this.serverUUID = serverUUID; this.providerName = providerName; @@ -56,8 +55,8 @@ public class StorePlayerGroupsResultTransaction extends Transaction { @Override protected void performOperations() { execute(deleteOldValues()); - for (Group group : value) { - String groupName = StringUtils.truncate(group.getGroupName(), 50); + for (String group : value) { + String groupName = StringUtils.truncate(group, 50); execute(insertGroup(groupName)); } } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/db/DatabaseTest.java b/Plan/common/src/test/java/com/djrapitops/plan/db/DatabaseTest.java index 713ceb1c1..3fb9c6b5d 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/db/DatabaseTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/db/DatabaseTest.java @@ -51,7 +51,10 @@ import com.djrapitops.plan.db.access.transactions.init.RemoveDuplicateUserInfoTr import com.djrapitops.plan.db.patches.Patch; import com.djrapitops.plan.db.sql.parsing.Sql; import com.djrapitops.plan.db.tasks.DBCleanTask; -import com.djrapitops.plan.extension.*; +import com.djrapitops.plan.extension.CallEvents; +import com.djrapitops.plan.extension.DataExtension; +import com.djrapitops.plan.extension.ExtensionService; +import com.djrapitops.plan.extension.ExtensionServiceImplementation; import com.djrapitops.plan.extension.annotation.*; import com.djrapitops.plan.extension.icon.Color; import com.djrapitops.plan.extension.icon.Icon; @@ -1465,8 +1468,8 @@ public interface DatabaseTest { @GroupProvider(text = "Conditional Group") @Conditional("condition") - public Group[] conditionalGroups(UUID playerUUID) { - return new Group[]{() -> "Group"}; + public String[] conditionalGroups(UUID playerUUID) { + return new String[]{"Group"}; } @StringProvider(text = "Unconditional") @@ -1531,8 +1534,8 @@ public interface DatabaseTest { } @GroupProvider(text = "a group") - public Group[] groupVal(UUID playerUUID) { - return new Group[]{() -> "Group"}; + public String[] groupVal(UUID playerUUID) { + return new String[]{"Group"}; } }