diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java index 1584c495..19b2831f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java @@ -6,8 +6,13 @@ import yapion.hierarchy.types.YAPIONObject; @UtilityClass public class ConfigCreator { + public static final int currentVersion = 1; + public YAPIONObject createDefaultConfig() { YAPIONObject yapionObject = new YAPIONObject(); + // This call should never be touched + yapionObject.add("@version", currentVersion); + // Any initialising goes into here return yapionObject; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java index 82e8264a..c48cd2f2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java @@ -44,4 +44,21 @@ public class ConfigUpdater implements Listener { public void save(Player player) { // Save call -> Database } + + private YAPIONObject update(YAPIONObject yapionObject) { + int version = yapionObject.getPlainValue("@version"); + while (version < ConfigCreator.currentVersion) { + ConfigConverter configConverter = CONFIG_CONVERTER_MAP.getOrDefault(version, null); + if (configConverter == null) { + return ConfigCreator.createDefaultConfig(); + } + try { + configConverter.update(yapionObject); + } catch (Exception e) { + return ConfigCreator.createDefaultConfig(); + } + version = yapionObject.getPlainValue("@version"); + } + return yapionObject; + } }