@@ -35,7 +35,7 @@ public class ConfigurationManager {
35
35
* @param config The class to register.
36
36
*/
37
37
public static void registerConfig (Class <?> config ) throws IllegalAccessException {
38
- val cfg = Optional .of (config .getAnnotation (Config .class )).orElseThrow (() -> new IllegalArgumentException ("Class " + config .getName () + " does not have a @Config annotation!" ));
38
+ val cfg = Optional .ofNullable (config .getAnnotation (Config .class )).orElseThrow (() -> new IllegalArgumentException ("Class " + config .getName () + " does not have a @Config annotation!" ));
39
39
val cfgSet = configs .computeIfAbsent (cfg .modid (), (ignored ) -> new HashSet <>());
40
40
cfgSet .add (config );
41
41
processConfig (config );
@@ -82,24 +82,24 @@ private static void processConfig(Class<?> configClass) throws IllegalAccessExce
82
82
for (val field : configClass .getDeclaredFields ()) {
83
83
if (field .getAnnotation (Config .Ignore .class ) != null ) continue ;
84
84
field .setAccessible (true );
85
- val comment = Optional .of (field .getAnnotation (Config .Comment .class )).map (Config .Comment ::value ).map ((lines ) -> String .join ("\n " , lines )).orElse ("" );
86
- val name = Optional .of (field .getAnnotation (Config .Name .class )).map (Config .Name ::value ).orElse (field .getName ());
87
- val langKey = Optional .of (field .getAnnotation (Config .LangKey .class )).map (Config .LangKey ::value ).orElse (name );
85
+ val comment = Optional .ofNullable (field .getAnnotation (Config .Comment .class )).map (Config .Comment ::value ).map ((lines ) -> String .join ("\n " , lines )).orElse ("" );
86
+ val name = Optional .ofNullable (field .getAnnotation (Config .Name .class )).map (Config .Name ::value ).orElse (field .getName ());
87
+ val langKey = Optional .ofNullable (field .getAnnotation (Config .LangKey .class )).map (Config .LangKey ::value ).orElse (name );
88
88
var boxed = false ;
89
89
Property prop = cat .get (name );
90
90
prop .comment = comment ;
91
91
prop .setLanguageKey (langKey );
92
92
if ((boxed = field .getType ().equals (Integer .class )) || field .getType ().equals (int .class )) {
93
- val range = Optional .of (field .getAnnotation (Config .RangeInt .class ));
93
+ val range = Optional .ofNullable (field .getAnnotation (Config .RangeInt .class ));
94
94
prop .setMinValue (range .map (Config .RangeInt ::min ).orElse (Integer .MIN_VALUE ));
95
95
prop .setMaxValue (range .map (Config .RangeInt ::max ).orElse (Integer .MAX_VALUE ));
96
- prop .setDefaultValue (Optional .of (field .getAnnotation (Config .DefaultInt .class )).map (Config .DefaultInt ::value ).orElse (boxed ? (Integer )field .get (null ) : field .getInt (null )));
96
+ prop .setDefaultValue (Optional .ofNullable (field .getAnnotation (Config .DefaultInt .class )).map (Config .DefaultInt ::value ).orElse (boxed ? (Integer )field .get (null ) : field .getInt (null )));
97
97
field .setInt (null , prop .getInt ());
98
98
} else if ((boxed = field .getType ().equals (Double .class )) || field .getType ().equals (double .class )) {
99
- val range = Optional .of (field .getAnnotation (Config .RangeDouble .class ));
99
+ val range = Optional .ofNullable (field .getAnnotation (Config .RangeDouble .class ));
100
100
prop .setMinValue (range .map (Config .RangeDouble ::min ).orElse (Double .MIN_VALUE ));
101
101
prop .setMaxValue (range .map (Config .RangeDouble ::max ).orElse (Double .MAX_VALUE ));
102
- prop .setDefaultValue (Optional .of (field .getAnnotation (Config .DefaultDouble .class )).map (Config .DefaultDouble ::value ).orElse (boxed ? (Double ) field .get (null ) : field .getDouble (null )));
102
+ prop .setDefaultValue (Optional .ofNullable (field .getAnnotation (Config .DefaultDouble .class )).map (Config .DefaultDouble ::value ).orElse (boxed ? (Double ) field .get (null ) : field .getDouble (null )));
103
103
field .setDouble (null , prop .getDouble ());
104
104
} else if ((boxed = field .getType ().equals (Boolean .class )) || field .getType ().equals (boolean .class )) {
105
105
prop .setDefaultValue (boxed ? (Boolean )field .get (null ) : field .getBoolean (null ));
0 commit comments