@@ -88,39 +88,39 @@ private static void processConfig(Class<?> configClass) throws IllegalAccessExce
88
88
val comment = Optional .ofNullable (field .getAnnotation (Config .Comment .class )).map (Config .Comment ::value ).map ((lines ) -> String .join ("\n " , lines )).orElse ("" );
89
89
val name = Optional .ofNullable (field .getAnnotation (Config .Name .class )).map (Config .Name ::value ).orElse (field .getName ());
90
90
val langKey = Optional .ofNullable (field .getAnnotation (Config .LangKey .class )).map (Config .LangKey ::value ).orElse (name );
91
+ val fieldClass = field .getType ();
91
92
var boxed = false ;
92
- if ((boxed = field . getType (). equals (Boolean .class )) || field . getType () .equals (boolean .class )) {
93
+ if ((boxed = fieldClass . equals (Boolean .class )) || fieldClass .equals (boolean .class )) {
93
94
val defaultValue = Optional .ofNullable (field .getAnnotation (Config .DefaultBoolean .class )).map (Config .DefaultBoolean ::value ).orElse (boxed ? (Boolean ) field .get (null ) : field .getBoolean (null ));
94
95
field .setBoolean (null , rawConfig .getBoolean (name , category , defaultValue , comment , langKey ));
95
- } else if ((boxed = field . getType (). equals (Integer .class )) || field . getType () .equals (int .class )) {
96
+ } else if ((boxed = fieldClass . equals (Integer .class )) || fieldClass .equals (int .class )) {
96
97
val range = Optional .ofNullable (field .getAnnotation (Config .RangeInt .class ));
97
98
val min = range .map (Config .RangeInt ::min ).orElse (Integer .MIN_VALUE );
98
99
val max = range .map (Config .RangeInt ::max ).orElse (Integer .MAX_VALUE );
99
100
val defaultValue = Optional .ofNullable (field .getAnnotation (Config .DefaultInt .class )).map (Config .DefaultInt ::value ).orElse (boxed ? (Integer )field .get (null ) : field .getInt (null ));
100
101
field .setInt (null , rawConfig .getInt (name , category , defaultValue , min , max , comment , langKey ));
101
- } else if ((boxed = field . getType (). equals (Float .class )) || field . getType () .equals (float .class )) {
102
+ } else if ((boxed = fieldClass . equals (Float .class )) || fieldClass .equals (float .class )) {
102
103
val range = Optional .ofNullable (field .getAnnotation (Config .RangeFloat .class ));
103
104
val min = range .map (Config .RangeFloat ::min ).orElse (Float .MIN_VALUE );
104
105
val max = range .map (Config .RangeFloat ::max ).orElse (Float .MAX_VALUE );
105
106
val defaultValue = Optional .ofNullable (field .getAnnotation (Config .DefaultFloat .class )).map (Config .DefaultFloat ::value ).orElse (boxed ? (Float ) field .get (null ) : field .getFloat (null ));
106
107
field .setDouble (null , rawConfig .getFloat (name , category , defaultValue , min , max , comment , langKey ));
107
- } else if (field . getType () .equals (String .class )) {
108
+ } else if (fieldClass .equals (String .class )) {
108
109
val defaultValue = Optional .ofNullable (field .getAnnotation (Config .DefaultString .class )).map (Config .DefaultString ::value ).orElse ((String )field .get (null ));
109
110
val pattern = Optional .ofNullable (field .getAnnotation (Config .Pattern .class )).map (Config .Pattern ::value ).map (Pattern ::compile ).orElse (null );
110
111
field .set (null , rawConfig .getString (name , category , defaultValue , comment , langKey , pattern ));
111
- } else if (field .isEnumConstant ()) {
112
- val enumClass = field .getType ();
113
- val enumValues = Arrays .stream ((Object [])enumClass .getDeclaredMethod ("values" ).invoke (null )).map ((obj ) -> (Enum <?>)obj ).collect (Collectors .toList ());
112
+ } else if (fieldClass .isEnum ()) {
113
+ val enumValues = Arrays .stream ((Object [])fieldClass .getDeclaredMethod ("values" ).invoke (null )).map ((obj ) -> (Enum <?>)obj ).collect (Collectors .toList ());
114
114
val defaultValue = (Enum <?>)
115
115
Optional .ofNullable (field .getAnnotation (Config .DefaultEnum .class ))
116
116
.map (Config .DefaultEnum ::value )
117
- .map ((defName ) -> extractField (enumClass , defName ))
117
+ .map ((defName ) -> extractField (fieldClass , defName ))
118
118
.map (ConfigurationManager ::extractValue )
119
119
.orElse (field .get (null ));
120
120
val possibleValues = enumValues .stream ().map (Enum ::name ).toArray (String []::new );
121
- field .set (null , enumClass .getDeclaredField (rawConfig .getString (name , category , defaultValue .name (), comment , possibleValues , langKey )));
121
+ field .set (null , fieldClass .getDeclaredField (rawConfig .getString (name , category , defaultValue .name (), comment , possibleValues , langKey )));
122
122
} else {
123
- throw new ConfigException ("Illegal config field: " + field .getName () + " in " + configClass .getName () + ": Unsupported type " + field . getType () .getName () + "! Did you forget an @Ignore annotation?" );
123
+ throw new ConfigException ("Illegal config field: " + field .getName () + " in " + configClass .getName () + ": Unsupported type " + fieldClass .getName () + "! Did you forget an @Ignore annotation?" );
124
124
}
125
125
if (field .isAnnotationPresent (Config .RequiresMcRestart .class )) {
126
126
cat .setRequiresMcRestart (true );
0 commit comments