From 4ca08401ff854399a0afb14595dce229807a6660 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Fri, 25 Jun 2021 20:10:45 +0200 Subject: [PATCH] Store fallback value when loading persistent data if data is missing --- .../spigot/wizcompat/serialization/PersistentData.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dev/w1zzrd/spigot/wizcompat/serialization/PersistentData.java b/src/dev/w1zzrd/spigot/wizcompat/serialization/PersistentData.java index 5d9047f..0197305 100644 --- a/src/dev/w1zzrd/spigot/wizcompat/serialization/PersistentData.java +++ b/src/dev/w1zzrd/spigot/wizcompat/serialization/PersistentData.java @@ -43,8 +43,14 @@ public class PersistentData { * @return Data at the given path, if available, else the default value */ public T loadData(final String path, final DefaultGetter defaultValue) { - final T value = (T) config.get(path); - return value == null ? defaultValue.get() : value; + T value = (T) config.get(path); + + if (value == null) { + value = defaultValue.get(); + config.set(path, value); + } + + return value; } /**