Store fallback value when loading persistent data if data is missing

This commit is contained in:
Gabriel Tofvesson 2021-06-25 20:10:45 +02:00
parent a27934b3d4
commit 4ca08401ff

View File

@ -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;
} }
/** /**