mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-11 11:27:29 +00:00
Merge pull request #3 from embeddedt/master
Add support for string list configs
This commit is contained in:
2 files changed
+10
No files matched your search
@@ -91,6 +91,12 @@ public @interface Config {
|
||||
String value();
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@interface DefaultStringList {
|
||||
String[] value();
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@interface Name {
|
||||
|
||||
@@ -155,6 +155,10 @@ public class ConfigurationManager {
|
||||
configClass.getName() + "! Using default value of " + defaultValue + "!");
|
||||
field.set(null, defaultValue);
|
||||
}
|
||||
} else if (fieldClass.isArray() && fieldClass.getComponentType().equals(String.class)) {
|
||||
val defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultStringList.class)).map(Config.DefaultStringList::value).orElse((String[])field.get(null));
|
||||
var value = rawConfig.getStringList(name, category, defaultValue, comment, null, langKey);
|
||||
field.set(null, value);
|
||||
} else {
|
||||
throw new ConfigException("Illegal config field: " + field.getName() + " in " + configClass.getName() +
|
||||
": Unsupported type " + fieldClass.getName() +
|
||||
|
||||
Reference in new issue
Block a user