mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-20 20:12:28 +00:00
Add a config version to config files.
Mostly because we need a way to generate missing entries when they got added.
This commit is contained in:
1 parent
a5b7f032cf
commit
09288895a0
2 files changed
+19
No files matched your search
@@ -30,6 +30,7 @@ public abstract class AbstractConfig {
|
||||
val.loader = configFile.loader;
|
||||
val.file = configFile.file;
|
||||
val.insertDefaults();
|
||||
val.setConfigVersion();
|
||||
|
||||
configFileList.add(val);
|
||||
// note: this is a workaround for generics because the generic info has to match the same class
|
||||
|
||||
@@ -29,6 +29,7 @@ import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
||||
import ninja.leaping.configurate.loader.AtomicFiles;
|
||||
import ninja.leaping.configurate.loader.ConfigurationLoader;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
import ninja.leaping.configurate.objectmapping.Setting;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;
|
||||
|
||||
@@ -42,6 +43,9 @@ public abstract class AbstractConfigFile implements Serializable {
|
||||
// if you want to use it, set it to false in your constructor or something ;o
|
||||
private boolean needsSaving = true;
|
||||
|
||||
@Setting("_VERSION")
|
||||
private int configVersion;
|
||||
|
||||
// required constructor for deserialization
|
||||
public AbstractConfigFile() {
|
||||
file = null;
|
||||
@@ -72,6 +76,20 @@ public abstract class AbstractConfigFile implements Serializable {
|
||||
|
||||
public abstract void insertDefaults();
|
||||
|
||||
/**
|
||||
* Return a number for the config version.
|
||||
* If the version number differs from the one in the file the file will be updated.
|
||||
* So if you add new fields etc. update the number
|
||||
*/
|
||||
protected abstract int getConfigVersion();
|
||||
|
||||
void setConfigVersion() {
|
||||
if(configVersion != getConfigVersion()) {
|
||||
configVersion = getConfigVersion();
|
||||
setNeedsSaving();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public AbstractConfigFile loadFromPacket(byte[] packetData) {
|
||||
ConfigurationLoader<CommentedConfigurationNode> packetDataLoader = HoconConfigurationLoader
|
||||
|
||||
Reference in new issue
Block a user