diff --git a/README.md b/README.md
index 7f5f638..2c9e1a5 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ This project is a GSON-like project for Bukkit's YML Config API. This project is
xyz.mkotb
config-api
- 1.0.1
+ 1.1.0
```
diff --git a/pom.xml b/pom.xml
index bd29d9c..ca72c23 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
xyz.mkotb
config-api
- 1.0.1
+ 1.1.0
ConfigAPI
GSON-like ORM for the Bukkit Config API
@@ -112,34 +112,37 @@
2.4
-
- com.mycila.maven-license-plugin
- maven-license-plugin
-
-
-
- true
- UTF-8
- true
-
-
- SLASHSTAR_STYLE
-
-
- license
-
-
- src/main/java/**
- src/test/java/**
-
-
- clean
-
- format
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/xyz/mkotb/configapi/ConfigFactory.java b/src/main/java/xyz/mkotb/configapi/ConfigFactory.java
index 7b4f1a9..3c695ed 100644
--- a/src/main/java/xyz/mkotb/configapi/ConfigFactory.java
+++ b/src/main/java/xyz/mkotb/configapi/ConfigFactory.java
@@ -34,7 +34,10 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
public final class ConfigFactory {
private volatile NamingStrategy namingStrategy = new CamelCaseNamingStrategy();
@@ -130,16 +133,32 @@ private T colourizeFields(T object) {
continue;
}
- if (field.getType() != String.class) {
- continue;
- }
-
- Coloured annotation = field.getDeclaredAnnotation(Coloured.class);
- String value = InternalsHelper.getField(field, object);
+ if (field.getType() == String.class) {
+ Coloured annotation = field.getDeclaredAnnotation(Coloured.class);
+ String value = InternalsHelper.getField(field, object);
- if (value != null) {
- InternalsHelper.setField(field, object, AdapterHandler.translateAlternateColorCodes(
- ChatColor.COLOR_CHAR, annotation.value(), value));
+ if (value != null) {
+ InternalsHelper.setField(field, object, AdapterHandler.translateAlternateColorCodes(
+ ChatColor.COLOR_CHAR, annotation.value(), value));
+ }
+ } else if (field.getType() == List.class) {
+ Class> genericType = (Class>) ((ParameterizedType) field.getGenericType())
+ .getActualTypeArguments()[0];
+
+ if (genericType.equals(String.class)) {
+ Coloured annotation = field.getDeclaredAnnotation(Coloured.class);
+ List value = InternalsHelper.getField(field, object);
+
+ if (value != null) {
+ List translated = value
+ .stream()
+ .map(s -> AdapterHandler.translateAlternateColorCodes(
+ ChatColor.COLOR_CHAR, annotation.value(), s
+ )).collect(Collectors.toList());
+
+ InternalsHelper.setField(field, object, translated);
+ }
+ }
}
}
diff --git a/src/main/java/xyz/mkotb/configapi/internal/adapt/AdapterHandler.java b/src/main/java/xyz/mkotb/configapi/internal/adapt/AdapterHandler.java
index 4d746b8..aeaaa3b 100644
--- a/src/main/java/xyz/mkotb/configapi/internal/adapt/AdapterHandler.java
+++ b/src/main/java/xyz/mkotb/configapi/internal/adapt/AdapterHandler.java
@@ -17,7 +17,7 @@
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
-import org.bukkit.enchantment.Enchantment;
+import org.bukkit.enchantments.Enchantment;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
@@ -35,9 +35,11 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.*;
+import java.util.stream.Collectors;
public final class AdapterHandler {
private static final Map, Class>> PRIMITIVE_BOXES = new ConcurrentHashMap<>();
@@ -198,6 +200,20 @@ public O adaptOut(I input, Class outClass, Class> type) {
obj = translateAlternateColorCodes(annotation.value(), ChatColor.COLOR_CHAR, (String) obj);
}
+ if (obj instanceof List && field.isAnnotationPresent(Coloured.class)) {
+ Class> genericType = (Class>) ((ParameterizedType) field.getGenericType())
+ .getActualTypeArguments()[0];
+
+ if (genericType.equals(String.class)) {
+ Coloured annotation = field.getDeclaredAnnotation(Coloured.class);
+ obj = ((List) obj)
+ .stream()
+ .map(text -> translateAlternateColorCodes(
+ annotation.value(), ChatColor.COLOR_CHAR, text)
+ ).collect(Collectors.toList());
+ }
+ }
+
section.set(namingStrategy.rename(field.getName()), obj);
}
}