Plan API 5.0-R0.2: Changed GroupProvider to return String[]

This commit is contained in:
Rsl1122 2019-08-27 13:01:12 +03:00
parent 41cec8a055
commit 6cbf28ad17
9 changed files with 26 additions and 27 deletions

View File

@ -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')

View File

@ -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.
* <p>
* This method annotation only works when used with {@code UUID} or {@code String} as a method parameter (for Players).
* <p>
* For example:
* {@code @GroupProvider public Group[] getJobs(UUID playerUUID) {}}
* {@code @GroupProvider public String[] getJobs(UUID playerUUID) {}}
* <p>
* Group data is parsed as Table for /server & /network page and similar to {@link StringProvider} for /player page.
* <p>

View File

@ -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);
}

View File

@ -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

View File

@ -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<Group[]> {
public class GroupDataProvider extends DataProvider<String[]> {
private GroupDataProvider(ProviderInformation providerInformation, MethodWrapper<Group[]> methodWrapper) {
private GroupDataProvider(ProviderInformation providerInformation, MethodWrapper<String[]> methodWrapper) {
super(providerInformation, methodWrapper);
}
@ -42,7 +41,7 @@ public class GroupDataProvider extends DataProvider<Group[]> {
DataProviders dataProviders, Method method, GroupProvider annotation,
Conditional condition, String tab, String pluginName
) {
MethodWrapper<Group[]> methodWrapper = new MethodWrapper<>(method, Group[].class);
MethodWrapper<String[]> methodWrapper = new MethodWrapper<>(method, String[].class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.groupColor());
ProviderInformation providerInformation = new ProviderInformation(

View File

@ -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<Group[]> groupProvider : dataProviders.getPlayerMethodsByType(Group[].class)) {
for (DataProvider<String[]> 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<Group[]> groupProvider
DataProvider<String[]> groupProvider
) {
ProviderInformation providerInformation = groupProvider.getProviderInformation();
Optional<String> condition = providerInformation.getCondition();
@ -74,9 +73,9 @@ class GroupProviderValueGatherer {
return;
}
MethodWrapper<Group[]> method = groupProvider.getMethod();
MethodWrapper<String[]> 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
}

View File

@ -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<Group[]> provider, UUID serverUUID) {
public StoreGroupProviderTransaction(DataProvider<String[]> provider, UUID serverUUID) {
this.serverUUID = serverUUID;
providerInformation = provider.getProviderInformation();
}

View File

@ -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));
}
}

View File

@ -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"};
}
}