@@ -195,7 +195,6 @@ public final boolean loadConfiguration(FileSection section) {
195
195
return false ;
196
196
197
197
this .file = getFile (fileName ).getAbsoluteFile ();
198
-
199
198
if (file .exists () && !file .isFile ()) {
200
199
logger .error ("The database file '" + file .getName () + "' does not exist or is a directory." , ErrorType .SEMANTIC_ERROR );
201
200
return false ;
@@ -225,15 +224,20 @@ public final boolean loadConfiguration(FileSection section) {
225
224
}
226
225
227
226
/**
228
- * Loads configurations and variables.
227
+ * Loads configurations and should start loading variables too .
229
228
*
230
229
* @return Whether the database could be loaded successfully,
231
230
* i.e. whether the configuration is correct and all variables could be loaded.
232
231
*/
233
232
protected abstract boolean load (FileSection section );
234
233
235
- protected void load (String name , SerializedVariable variable ) {
236
- load (name , variable .value .type , variable .value .data );
234
+ protected void loadVariable (String name , SerializedVariable variable ) {
235
+ Value value = variable .value ;
236
+ if (value == null ) {
237
+ Variables .queueVariableChange (name , null );
238
+ return ;
239
+ }
240
+ loadVariable (name , value .type , value .data );
237
241
}
238
242
239
243
/**
@@ -243,7 +247,7 @@ protected void load(String name, SerializedVariable variable) {
243
247
* @param type the type of the variable.
244
248
* @param value the serialized value of the variable.
245
249
*/
246
- protected void load (String name , @ NotNull String type , @ NotNull byte [] value ) {
250
+ protected void loadVariable (String name , @ NotNull String type , @ NotNull byte [] value ) {
247
251
if (value == null || type == null )
248
252
throw new IllegalArgumentException ("value and/or typeName cannot be null" );
249
253
Variables .queueVariableChange (name , deserialize (type , value ));
@@ -298,9 +302,9 @@ boolean accept(@Nullable String variableName) {
298
302
* @return the serialized variable.
299
303
*/
300
304
@ SuppressWarnings ("unchecked" )
301
- public <T > SerializedVariable serialize (String name , @ NotNull T value ) {
305
+ public <T > SerializedVariable serialize (String name , @ Nullable T value ) {
302
306
if (value == null )
303
- throw new IllegalArgumentException ( "value cannot be null" );
307
+ return new SerializedVariable ( name , null );
304
308
Type <T > type = (Type <T >) TypeManager .getByClassExact (value .getClass ()).orElse (null );
305
309
if (type == null )
306
310
throw new UnsupportedOperationException ("Class '" + value .getClass ().getName () + "' cannot be serialized. No type registered." );
0 commit comments