mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-11 07:47:46 +00:00
45 lines
1.1 KiB
Java
45 lines
1.1 KiB
Java
package com.gtnewhorizon.structurelib;
|
|
|
|
import net.minecraftforge.common.config.Configuration;
|
|
|
|
import javax.annotation.Nullable;
|
|
import java.util.Arrays;
|
|
import java.util.Objects;
|
|
|
|
enum ConfigurationVersion {
|
|
V1 {
|
|
@Override
|
|
protected void step(Configuration c) {
|
|
}
|
|
};
|
|
|
|
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) {
|
|
return Arrays.stream(VALUES).filter(v -> Objects.equals(c.getLoadedConfigVersion(), v.getVersionMarker())).findFirst().orElse(V1);
|
|
}
|
|
|
|
@Nullable
|
|
public String getVersionMarker() {
|
|
return versionMarker;
|
|
}
|
|
|
|
protected abstract void step(Configuration c);
|
|
}
|