Merge branch 'development' into feature/command_cleanup
# Conflicts: # src/de/craftinc/gates/models/Gate.java
This commit is contained in:
commit
8a199b4074
@ -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;
|
||||
|
@ -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;
|
||||
@ -249,44 +248,18 @@ public class Gate implements ConfigurationSerializable {
|
||||
static private String exitKey = "exit";
|
||||
static private String materialKey = "material";
|
||||
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<String, Object> map) {
|
||||
try {
|
||||
id = map.get(idKey).toString().toLowerCase();
|
||||
location = (Location) map.get(locationKey);
|
||||
exit = (Location) map.get(exitKey);
|
||||
|
||||
isOpen = (Boolean) map.get(isOpenKey);
|
||||
|
||||
location = LocationUtil.deserializeLocation((Map<String, Object>) map.get(locationKey));
|
||||
exit = LocationUtil.deserializeLocation((Map<String, Object>) map.get(exitKey));
|
||||
material = new GateMaterial((String)map.get(materialKey));
|
||||
|
||||
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<Map<String, Object>> serializedGateBlocks = (List<Map<String, Object>>) map.get(gateBlocksKey);
|
||||
|
||||
for (Map<String, Object> sgb : serializedGateBlocks) {
|
||||
gateBlockLocations.add(LocationUtil.deserializeLocation(sgb));
|
||||
}
|
||||
gateBlockLocations = (Set<Location>) map.get(gateBlocksKey);
|
||||
|
||||
gateFrameBlocks = FloodUtil.getFrameWithLocations(gateBlockLocations);
|
||||
} catch (Exception e) {
|
||||
@ -303,35 +276,23 @@ public class Gate implements ConfigurationSerializable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> retVal = new HashMap<>();
|
||||
|
||||
retVal.put(idKey, id);
|
||||
retVal.put(locationKey, LocationUtil.serializeLocation(location));
|
||||
retVal.put(exitKey, LocationUtil.serializeLocation(exit));
|
||||
retVal.put(isOpenKey, isOpen);
|
||||
retVal.put(allowsVehiclesKey, allowsVehicles);
|
||||
retVal.put(materialKey, material.toString());
|
||||
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<Map<String, Object>> serializedGateBlocks = new ArrayList<>();
|
||||
|
||||
for (Location l : gateBlockLocations) {
|
||||
serializedGateBlocks.add(LocationUtil.serializeLocation(l));
|
||||
}
|
||||
|
||||
retVal.put(gateBlocksKey, serializedGateBlocks);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<String, Object> serializeLocation(final Location l) {
|
||||
if (l == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, Object> 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<String, Object> 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());
|
||||
}
|
||||
}
|
@ -30,37 +30,11 @@ import java.util.logging.Level;
|
||||
public class MigrationUtil {
|
||||
|
||||
public static boolean performMigration(int storageVersion, int currentVersion, List<Gate> 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<Gate> 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<Gate> gates) {
|
||||
for (Gate g : gates) {
|
||||
g.setAllowsVehicles(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user