Added a storage migration class.
This commit is contained in:
parent
c3a24a940f
commit
d9194c7497
@ -20,7 +20,9 @@ public class GatesManager
|
|||||||
{
|
{
|
||||||
private File gatesConfigFile;
|
private File gatesConfigFile;
|
||||||
private FileConfiguration gatesConfig;
|
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<String, Gate> gatesById;
|
private Map<String, Gate> gatesById;
|
||||||
private Map<SimpleChunk, Set<Gate>> gatesByChunk;
|
private Map<SimpleChunk, Set<Gate>> gatesByChunk;
|
||||||
@ -52,6 +54,7 @@ public class GatesManager
|
|||||||
public void saveGatesToDisk()
|
public void saveGatesToDisk()
|
||||||
{
|
{
|
||||||
gatesConfig.set(gatesPath, new ArrayList<Object>(gatesById.values()));
|
gatesConfig.set(gatesPath, new ArrayList<Object>(gatesById.values()));
|
||||||
|
gatesConfig.set(storageVersionPath, storageVersion);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
gatesConfig.save(gatesConfigFile);
|
gatesConfig.save(gatesConfigFile);
|
||||||
@ -95,6 +98,14 @@ public class GatesManager
|
|||||||
fillGatesByLocation();
|
fillGatesByLocation();
|
||||||
|
|
||||||
Plugin.log("Loaded " + this.gates.size() + " gates.");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
33
src/de/craftinc/gates/MigrationUtil.java
Normal file
33
src/de/craftinc/gates/MigrationUtil.java
Normal file
@ -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<Gate> 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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user