From 9b0845f2c3791ed9cb68c2a883502279e391170e Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 17 Apr 2013 11:53:55 +0200 Subject: [PATCH] Improve the PS deserialization logic so it understands LazyLocation from older versions of Factions. --- .../mcore/cmd/VersionCommand.java | 2 +- src/com/massivecraft/mcore/ps/PS.java | 131 +++++++++++------- 2 files changed, 85 insertions(+), 48 deletions(-) diff --git a/src/com/massivecraft/mcore/cmd/VersionCommand.java b/src/com/massivecraft/mcore/cmd/VersionCommand.java index ca727e35..b2addaee 100644 --- a/src/com/massivecraft/mcore/cmd/VersionCommand.java +++ b/src/com/massivecraft/mcore/cmd/VersionCommand.java @@ -32,7 +32,7 @@ public class VersionCommand extends MCommand { this.addRequirements(ReqHasPerm.get(permissionName)); } - this.setDesc("display the plugin version"); + this.setDesc("display plugin version"); this.addAliases(aliases); } diff --git a/src/com/massivecraft/mcore/ps/PS.java b/src/com/massivecraft/mcore/ps/PS.java index e44c4a2d..dd1af413 100644 --- a/src/com/massivecraft/mcore/ps/PS.java +++ b/src/com/massivecraft/mcore/ps/PS.java @@ -343,57 +343,94 @@ public final class PS implements Cloneable, Serializable, Comparable final JsonObject jsonObject = jsonElement.getAsJsonObject(); final PSBuilder builder = new PSBuilder(); - for (Entry entry : jsonObject.entrySet()) + + if (jsonObject.has("world") && jsonObject.has("yaw")) { - final String key = entry.getKey(); - final JsonElement value = entry.getValue(); - - switch(key) + // Old Faction LazyLocation + for (Entry entry : jsonObject.entrySet()) { - case NAME_SERIALIZED_WORLD: - builder.world(value.getAsString()); - break; - case NAME_SERIALIZED_BLOCKX: - builder.blockX(value.getAsInt()); - break; - case NAME_SERIALIZED_BLOCKY: - builder.blockY(value.getAsInt()); - break; - case NAME_SERIALIZED_BLOCKZ: - builder.blockZ(value.getAsInt()); - break; - case NAME_SERIALIZED_LOCATIONX: - builder.locationX(value.getAsDouble()); - break; - case NAME_SERIALIZED_LOCATIONY: - builder.locationY(value.getAsDouble()); - break; - case NAME_SERIALIZED_LOCATIONZ: - builder.locationZ(value.getAsDouble()); - break; - case NAME_SERIALIZED_CHUNKX: - builder.chunkX(value.getAsInt()); - break; - case NAME_SERIALIZED_CHUNKZ: - builder.chunkZ(value.getAsInt()); - break; - case NAME_SERIALIZED_PITCH: - builder.pitch(value.getAsFloat()); - break; - case NAME_SERIALIZED_YAW: - builder.yaw(value.getAsFloat()); - break; - case NAME_SERIALIZED_VELOCITYX: - builder.velocityX(value.getAsDouble()); - break; - case NAME_SERIALIZED_VELOCITYY: - builder.velocityY(value.getAsDouble()); - break; - case NAME_SERIALIZED_VELOCITYZ: - builder.velocityZ(value.getAsDouble()); - break; + final String key = entry.getKey(); + final JsonElement value = entry.getValue(); + + switch(key) + { + case "world": + builder.world(value.getAsString()); + break; + case "x": + builder.locationX(value.getAsDouble()); + break; + case "y": + builder.locationY(value.getAsDouble()); + break; + case "z": + builder.locationZ(value.getAsDouble()); + break; + case "pitch": + builder.pitch(value.getAsFloat()); + break; + case "yaw": + builder.yaw(value.getAsFloat()); + break; + } } } + else + { + // The Standard Format + for (Entry entry : jsonObject.entrySet()) + { + final String key = entry.getKey(); + final JsonElement value = entry.getValue(); + + switch(key) + { + case NAME_SERIALIZED_WORLD: + builder.world(value.getAsString()); + break; + case NAME_SERIALIZED_BLOCKX: + builder.blockX(value.getAsInt()); + break; + case NAME_SERIALIZED_BLOCKY: + builder.blockY(value.getAsInt()); + break; + case NAME_SERIALIZED_BLOCKZ: + builder.blockZ(value.getAsInt()); + break; + case NAME_SERIALIZED_LOCATIONX: + builder.locationX(value.getAsDouble()); + break; + case NAME_SERIALIZED_LOCATIONY: + builder.locationY(value.getAsDouble()); + break; + case NAME_SERIALIZED_LOCATIONZ: + builder.locationZ(value.getAsDouble()); + break; + case NAME_SERIALIZED_CHUNKX: + builder.chunkX(value.getAsInt()); + break; + case NAME_SERIALIZED_CHUNKZ: + builder.chunkZ(value.getAsInt()); + break; + case NAME_SERIALIZED_PITCH: + builder.pitch(value.getAsFloat()); + break; + case NAME_SERIALIZED_YAW: + builder.yaw(value.getAsFloat()); + break; + case NAME_SERIALIZED_VELOCITYX: + builder.velocityX(value.getAsDouble()); + break; + case NAME_SERIALIZED_VELOCITYY: + builder.velocityY(value.getAsDouble()); + break; + case NAME_SERIALIZED_VELOCITYZ: + builder.velocityZ(value.getAsDouble()); + break; + } + } + } + return builder.build(); }