diff --git a/src/de/craftinc/gates/GatesManager.java b/src/de/craftinc/gates/GatesManager.java index 5af5228..5cebd5a 100644 --- a/src/de/craftinc/gates/GatesManager.java +++ b/src/de/craftinc/gates/GatesManager.java @@ -20,7 +20,9 @@ public class GatesManager { private File gatesConfigFile; private FileConfiguration gatesConfig; - private String gatesPath = "gates"; // path to gates inside the yaml file + private static final String gatesPath = "gates"; // path to gates inside the yaml file + private static final String storageVersionPath = "version"; + private static final int storageVersion = 1; private Map gatesById; private Map> gatesByChunk; @@ -52,6 +54,7 @@ public class GatesManager public void saveGatesToDisk() { gatesConfig.set(gatesPath, new ArrayList(gatesById.values())); + gatesConfig.set(storageVersionPath, storageVersion); try { gatesConfig.save(gatesConfigFile); @@ -95,6 +98,14 @@ public class GatesManager fillGatesByLocation(); Plugin.log("Loaded " + this.gates.size() + " gates."); + + // migration + int fileStorageVersion = gatesConfig.getInt(storageVersionPath); + + if (fileStorageVersion < storageVersion) { + Plugin.log("Outdated storage version detected. Performing data migration..."); + MigrationUtil.performMigration(fileStorageVersion, storageVersion, this.gates); + } } diff --git a/src/de/craftinc/gates/MigrationUtil.java b/src/de/craftinc/gates/MigrationUtil.java new file mode 100644 index 0000000..e744efc --- /dev/null +++ b/src/de/craftinc/gates/MigrationUtil.java @@ -0,0 +1,33 @@ +package de.craftinc.gates; + +import de.craftinc.gates.Gate; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; + +import java.util.List; + + +public class MigrationUtil +{ + public static void performMigration(int storageVersion, int currentVersion, List gates) + { + if (currentVersion == 1 && storageVersion == 0) { + + for (Gate g : gates) { + + for (Location l : g.getGateBlockLocations()) { + Block b = l.getBlock(); + + if (b.getType() == Material.PORTAL) { + b.setType(Material.AIR); + } + } + } + } + else { + throw new IllegalArgumentException("Supplied storage version is currently not supported! Make sure you have the latest version of Craft Inc. Gates installed."); + } + } +}