2021-07-21 17:26:28 +08:00
|
|
|
package com.gtnewhorizon.structurelib;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Objects;
|
2022-08-08 17:40:12 +08:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
import net.minecraftforge.common.config.Configuration;
|
2021-07-21 17:26:28 +08:00
|
|
|
|
|
|
|
|
enum ConfigurationVersion {
|
|
|
|
|
V1 {
|
|
|
|
|
@Override
|
2022-08-08 17:40:12 +08:00
|
|
|
protected void step(Configuration c) {}
|
2021-07-21 17:26:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static final ConfigurationVersion[] VALUES = values();
|
|
|
|
|
|
|
|
|
|
private final String versionMarker;
|
|
|
|
|
|
|
|
|
|
ConfigurationVersion() {
|
|
|
|
|
this.versionMarker = name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void migrateToLatest(Configuration c) {
|
|
|
|
|
for (int i = identify(c).ordinal() + 1; i < VALUES.length; i++) {
|
|
|
|
|
VALUES[i].step(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ConfigurationVersion latest() {
|
|
|
|
|
return VALUES[VALUES.length - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ConfigurationVersion identify(Configuration c) {
|
2022-08-08 17:40:12 +08:00
|
|
|
return Arrays.stream(VALUES)
|
|
|
|
|
.filter(v -> Objects.equals(c.getLoadedConfigVersion(), v.getVersionMarker()))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(V1);
|
2021-07-21 17:26:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
|
public String getVersionMarker() {
|
|
|
|
|
return versionMarker;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract void step(Configuration c);
|
|
|
|
|
}
|