diff --git a/src/de/craftinc/gates/controllers/GatesManager.java b/src/de/craftinc/gates/controllers/GatesManager.java index 99a96b6..c575b99 100644 --- a/src/de/craftinc/gates/controllers/GatesManager.java +++ b/src/de/craftinc/gates/controllers/GatesManager.java @@ -41,7 +41,7 @@ public class GatesManager { private static final String gatesPath = "gates"; // path to gates inside the yaml file private static final String storageVersionPath = "version"; - private static final int storageVersion = 2; + private static final int storageVersion = 3; private File gatesConfigFile; private FileConfiguration gatesConfig; diff --git a/src/de/craftinc/gates/models/Gate.java b/src/de/craftinc/gates/models/Gate.java index 14f83d1..c063360 100644 --- a/src/de/craftinc/gates/models/Gate.java +++ b/src/de/craftinc/gates/models/Gate.java @@ -19,7 +19,6 @@ package de.craftinc.gates.models; import de.craftinc.gates.Plugin; import de.craftinc.gates.util.ConfigurationUtil; import de.craftinc.gates.util.FloodUtil; -import de.craftinc.gates.persistence.LocationUtil; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -232,7 +231,6 @@ public class Gate implements ConfigurationSerializable { } } - /* * INTERFACE: ConfigurationSerializable */ @@ -242,44 +240,18 @@ public class Gate implements ConfigurationSerializable { static private String exitKey = "exit"; static private String isHiddenKey = "hidden"; static private String isOpenKey = "open"; - static private String locationYawKey = "locationYaw"; - static private String locationPitchKey = "locationPitch"; - static private String exitYawKey = "exitYaw"; - static private String exitPitchKey = "exitPitch"; static private String allowsVehiclesKey = "allowsVehiclesKey"; - @SuppressWarnings("unchecked") public Gate(Map map) { try { id = map.get(idKey).toString().toLowerCase(); - + location = (Location) map.get(locationKey); + exit = (Location) map.get(exitKey); isHidden = (Boolean) map.get(isHiddenKey); isOpen = (Boolean) map.get(isOpenKey); - - location = LocationUtil.deserializeLocation((Map) map.get(locationKey)); - exit = LocationUtil.deserializeLocation((Map) map.get(exitKey)); - - if (map.containsKey(exitPitchKey)) { - exit.setPitch(((Number) map.get(exitPitchKey)).floatValue()); - exit.setYaw(((Number) map.get(exitYawKey)).floatValue()); - } - - if (map.containsKey(locationPitchKey)) { - location.setPitch(((Number) map.get(locationPitchKey)).floatValue()); - location.setYaw(((Number) map.get(locationYawKey)).floatValue()); - } - - if (map.containsKey(allowsVehiclesKey)) { - allowsVehicles = (Boolean) map.get(allowsVehiclesKey); - } - - gateBlockLocations = new HashSet<>(); - List> serializedGateBlocks = (List>) map.get(gateBlocksKey); - - for (Map sgb : serializedGateBlocks) { - gateBlockLocations.add(LocationUtil.deserializeLocation(sgb)); - } + allowsVehicles = (Boolean) map.get(allowsVehiclesKey); + gateBlockLocations = (Set) map.get(gateBlocksKey); gateFrameBlocks = FloodUtil.getFrameWithLocations(gateBlockLocations); } catch (Exception e) { @@ -296,35 +268,23 @@ public class Gate implements ConfigurationSerializable { } } - public Map serialize() { Map retVal = new HashMap<>(); retVal.put(idKey, id); - retVal.put(locationKey, LocationUtil.serializeLocation(location)); - retVal.put(exitKey, LocationUtil.serializeLocation(exit)); retVal.put(isHiddenKey, isHidden); retVal.put(isOpenKey, isOpen); retVal.put(allowsVehiclesKey, allowsVehicles); + retVal.put(gateBlocksKey, gateBlockLocations); if (exit != null) { - retVal.put(exitPitchKey, exit.getPitch()); - retVal.put(exitYawKey, exit.getYaw()); + retVal.put(exitKey, exit.serialize()); } if (location != null) { - retVal.put(locationPitchKey, location.getPitch()); - retVal.put(locationYawKey, location.getYaw()); + retVal.put(locationKey, location.serialize()); } - List> serializedGateBlocks = new ArrayList<>(); - - for (Location l : gateBlockLocations) { - serializedGateBlocks.add(LocationUtil.serializeLocation(l)); - } - - retVal.put(gateBlocksKey, serializedGateBlocks); - return retVal; } } diff --git a/src/de/craftinc/gates/persistence/LocationUtil.java b/src/de/craftinc/gates/persistence/LocationUtil.java deleted file mode 100644 index 4886cc4..0000000 --- a/src/de/craftinc/gates/persistence/LocationUtil.java +++ /dev/null @@ -1,93 +0,0 @@ -/* Craft Inc. Gates - Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program (LGPLv3). If not, see . -*/ -package de.craftinc.gates.persistence; - -import java.util.HashMap; -import java.util.Map; - -import org.bukkit.Location; -import org.bukkit.World; - -import de.craftinc.gates.Plugin; - -public class LocationUtil { - - private final static String worldKey = "world"; - private final static String xKey = "x"; - private final static String yKey = "y"; - private final static String zKey = "z"; - - private static World getWorld(final String name) throws Exception { - if (name == null) { - throw new IllegalArgumentException("The name of the world must not be 'null"); - } - - World world = Plugin.getPlugin().getServer().getWorld(name); - - if (world == null) { - throw new Exception("World '" + name + "' does not exists anymore! Cannot get instance!"); - } - - return world; - } - - /** - * Serializes a location. Helps storing locations inside yaml files. NOTE: We do not care about yaw - * and pitch for gate locations. So we won't serialize them. - * - * @param l The location to serialize. Supplying 'null' is ok.. - * @return A Map object ready for storing inside a yaml file. Will return 'null' if 'l' is null. - */ - public static Map serializeLocation(final Location l) { - if (l == null) { - return null; - } - - Map serializedLocation = new HashMap<>(); - - serializedLocation.put(worldKey, l.getWorld().getName()); - serializedLocation.put(xKey, l.getX()); - serializedLocation.put(yKey, l.getY()); - serializedLocation.put(zKey, l.getZ()); - - return serializedLocation; - } - - /** - * @param map A map generated with the 'serializeLocation' method. Supplying 'null' is ok. - * @return A deserialized location. This method will return 'null' if 'map' is null! - * @throws Exception This method will throw an exception if the world of the supplied serialized location - * does not exist or if 'map' does not contain all necessary keys! - */ - public static Location deserializeLocation(final Map map) throws Exception { - if (map == null) { - return null; - } - - World w = getWorld((String) map.get(worldKey)); - - Number x = (Number) map.get(xKey); - Number y = (Number) map.get(yKey); - Number z = (Number) map.get(zKey); - - if (x == null || y == null || z == null) { - throw new IllegalArgumentException("Supplied map is invalid x, y or z coordinate was not supplied"); - } - - return new Location(w, x.doubleValue(), y.doubleValue(), z.doubleValue()); - } -} diff --git a/src/de/craftinc/gates/persistence/MigrationUtil.java b/src/de/craftinc/gates/persistence/MigrationUtil.java index 46efe73..e3e657e 100644 --- a/src/de/craftinc/gates/persistence/MigrationUtil.java +++ b/src/de/craftinc/gates/persistence/MigrationUtil.java @@ -30,37 +30,11 @@ import java.util.logging.Level; public class MigrationUtil { public static boolean performMigration(int storageVersion, int currentVersion, List gates) { - if (storageVersion == 0 && currentVersion >= 2) { - removePortalBlocks(gates); - updateAllowVehicles(gates); - - return true; - } else if (storageVersion == 1 && currentVersion >= 2) { - updateAllowVehicles(gates); - - return true; - } else { - Plugin.log(Level.SEVERE, "Supplied storage version is currently not supported! Make sure you have the latest version of Craft Inc. Gates installed. Plugin will be disabled!"); + if (storageVersion != currentVersion) { + Plugin.log(Level.SEVERE, "Supplied storage version is currently not supported!" + + "Make sure you have the latest version of Craft Inc. Gates installed. Plugin will be disabled!"); return false; } - } - - private static void removePortalBlocks(List gates) { - for (Gate g : gates) { - - for (Location l : g.getGateBlockLocations()) { - Block b = l.getBlock(); - - if (b.getType() == Material.PORTAL) { - b.setType(Material.AIR); - } - } - } - } - - private static void updateAllowVehicles(List gates) { - for (Gate g : gates) { - g.setAllowsVehicles(true); - } + return true; } }