diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/config/Advanced.java b/common/src/main/java/xyz/jpenilla/squaremap/common/config/Advanced.java index 126a5395..678fa2ce 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/config/Advanced.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/config/Advanced.java @@ -2,7 +2,11 @@ import io.leangen.geantyref.TypeToken; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Set; +import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.NodePath; import org.spongepowered.configurate.transformation.ConfigurationTransformation; @@ -11,8 +15,10 @@ @SuppressWarnings("unused") public final class Advanced extends AbstractConfig { + private static final int LATEST_VERSION = 3; + Advanced(final DirectoryProvider directoryProvider) { - super(directoryProvider.dataDirectory(), Advanced.class, "advanced.yml", 2); + super(directoryProvider.dataDirectory(), Advanced.class, "advanced.yml", LATEST_VERSION); } @Override @@ -33,8 +39,47 @@ protected void addVersions(ConfigurationTransformation.VersionedBuilder versione return null; }) .build(); + final ConfigurationTransformation twoToThree = ConfigurationTransformation.builder() + .addAction(NodePath.path("world-settings"), (path, node) -> { + final Set childKeys = node.childrenMap().keySet(); + for (final Object childKey : childKeys) { + final ConfigurationNode worldSection = node.node(childKey); + final List sections = List.of( + worldSection.node("invisible-blocks"), + worldSection.node("iterate-up-base-blocks"), + worldSection.node("color-overrides", "blocks") + ); + for (final ConfigurationNode sectionNode : sections) { + if (sectionNode.isList()) { + final List list = Objects.requireNonNull(sectionNode.getList(String.class)); + boolean removed = false; + removed |= list.remove("minecraft:grass"); + removed |= list.remove("grass"); + if (removed) { + list.add("minecraft:short_grass"); + sectionNode.setList(String.class, list); + } + } else if (sectionNode.isMap()) { + final TypeToken> type = new TypeToken<>() {}; + final Map map = Objects.requireNonNull(sectionNode.get(type)); + @Nullable String removed; + removed = map.remove("minecraft:grass"); + if (removed == null) { + removed = map.remove("grass"); + } + if (removed != null) { + map.put("minecraft:short_grass", removed); + sectionNode.set(type, map); + } + } + } + } + return null; + }) + .build(); versionedBuilder.addVersion(2, oneToTwo); + versionedBuilder.addVersion(LATEST_VERSION, twoToThree); } static Advanced config; diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/config/Config.java b/common/src/main/java/xyz/jpenilla/squaremap/common/config/Config.java index 88c1fb92..ba97a92e 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/config/Config.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/config/Config.java @@ -8,8 +8,10 @@ @SuppressWarnings("unused") public final class Config extends AbstractConfig { + private static final int LATEST_VERSION = 2; + Config(final DirectoryProvider directoryProvider) { - super(directoryProvider.dataDirectory(), Config.class, "config.yml", 2); + super(directoryProvider.dataDirectory(), Config.class, "config.yml", LATEST_VERSION); } @Override @@ -24,7 +26,7 @@ protected void addVersions(final ConfigurationTransformation.VersionedBuilder ve }) .build(); - versionedBuilder.addVersion(2, oneToTwo); + versionedBuilder.addVersion(LATEST_VERSION, oneToTwo); } static Config config; diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldAdvanced.java b/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldAdvanced.java index cd205061..65c8a346 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldAdvanced.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldAdvanced.java @@ -33,7 +33,7 @@ private void invisibleBlocks() { List.of( "minecraft:tall_grass", "minecraft:fern", - "minecraft:grass", + "minecraft:short_grass", "minecraft:large_fern" ) ).forEach(block -> this.invisibleBlocks.add(Util.requireEntry(BuiltInRegistries.BLOCK, new ResourceLocation(block))));