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
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren