Store fallback value when loading persistent data if data is missing
This commit is contained in:
parent
a27934b3d4
commit
4ca08401ff
@ -43,8 +43,14 @@ public class PersistentData {
|
|||||||
* @return Data at the given path, if available, else the default value
|
* @return Data at the given path, if available, else the default value
|
||||||
*/
|
*/
|
||||||
public <T extends ConfigurationSerializable> T loadData(final String path, final DefaultGetter<T> defaultValue) {
|
public <T extends ConfigurationSerializable> T loadData(final String path, final DefaultGetter<T> defaultValue) {
|
||||||
final T value = (T) config.get(path);
|
T value = (T) config.get(path);
|
||||||
return value == null ? defaultValue.get() : value;
|
|
||||||
|
if (value == null) {
|
||||||
|
value = defaultValue.get();
|
||||||
|
config.set(path, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user