SteamWar/BauSystem2.0
Archiviert
12
0

Add ConfigCreator.createDefaultConfig

Add ConfigCreator.currentVersion
Add ConfigUpdater.update
Dieser Commit ist enthalten in:
yoyosource 2021-04-29 10:30:32 +02:00
Ursprung 9bad0d47b8
Commit e12bedec6c
2 geänderte Dateien mit 22 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -6,8 +6,13 @@ import yapion.hierarchy.types.YAPIONObject;
@UtilityClass @UtilityClass
public class ConfigCreator { public class ConfigCreator {
public static final int currentVersion = 1;
public YAPIONObject createDefaultConfig() { public YAPIONObject createDefaultConfig() {
YAPIONObject yapionObject = new YAPIONObject(); YAPIONObject yapionObject = new YAPIONObject();
// This call should never be touched
yapionObject.add("@version", currentVersion);
// Any initialising goes into here // Any initialising goes into here
return yapionObject; return yapionObject;
} }

Datei anzeigen

@ -44,4 +44,21 @@ public class ConfigUpdater implements Listener {
public void save(Player player) { public void save(Player player) {
// Save call -> Database // 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;
}
} }