Skip to content

Commit ffa5e4b

Browse files
committed
Add support for string list configs
1 parent 4cea2cd commit ffa5e4b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/main/java/com/falsepattern/lib/config/Config.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@
8787
String value();
8888
}
8989

90+
@Retention(RetentionPolicy.RUNTIME)
91+
@Target(ElementType.FIELD)
92+
@interface DefaultStringList {
93+
String[] value();
94+
}
95+
9096
@Retention(RetentionPolicy.RUNTIME)
9197
@Target(ElementType.FIELD)
9298
@interface Name {

src/main/java/com/falsepattern/lib/config/ConfigurationManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ private static void processConfigInternal(Class<?> configClass, String category,
172172
FalsePatternLib.getLog().warn("Invalid value " + value + " for enum configuration field " + field.getName() + " of type " + fieldClass.getName() + " in config class " + configClass.getName() + "! Using default value of " + defaultValue + "!");
173173
field.set(null, defaultValue);
174174
}
175+
} else if (fieldClass.isArray() && fieldClass.getComponentType().equals(String.class)) {
176+
val defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultStringList.class)).map(Config.DefaultStringList::value).orElse((String[])field.get(null));
177+
var value = rawConfig.getStringList(name, category, defaultValue, comment, null, langKey);
178+
field.set(null, value);
175179
} else {
176180
throw new ConfigException("Illegal config field: " + field.getName() + " in " + configClass.getName() + ": Unsupported type " + fieldClass.getName() + "! Did you forget an @Ignore annotation?");
177181
}

0 commit comments

Comments
 (0)