Add ConfigCreator.createDefaultConfig
Add ConfigCreator.currentVersion Add ConfigUpdater.update
Dieser Commit ist enthalten in:
Ursprung
9bad0d47b8
Commit
e12bedec6c
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren