summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/bukkit/Location.java38
-rw-r--r--src/main/java/org/bukkit/configuration/serialization/ConfigurationSerialization.java2
2 files changed, 39 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java
index 37fecc10..2a6b3942 100644
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -1,13 +1,17 @@
package org.bukkit;
+import java.util.HashMap;
+import java.util.Map;
+
import org.bukkit.block.Block;
+import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.util.NumberConversions;
import org.bukkit.util.Vector;
/**
* Represents a 3-dimensional position in a world
*/
-public class Location implements Cloneable {
+public class Location implements Cloneable, ConfigurationSerializable {
private World world;
private double x;
private double y;
@@ -560,4 +564,36 @@ public class Location implements Cloneable {
public static int locToBlock(double loc) {
return NumberConversions.floor(loc);
}
+
+ @Utility
+ public Map<String, Object> serialize() {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("world", this.world.getName());
+
+ data.put("x", this.x);
+ data.put("y", this.y);
+ data.put("z", this.z);
+
+ data.put("yaw", this.yaw);
+ data.put("pitch", this.pitch);
+
+ return data;
+ }
+
+ /**
+ * Required method for deserialization
+ *
+ * @param args map to deserialize
+ * @return deserialized location
+ * @throws IllegalArgumentException if the world don't exists
+ * @see ConfigurationSerializable
+ */
+ public static Location deserialize(Map<String, Object> args) {
+ World world = Bukkit.getWorld((String) args.get("world"));
+ if (world == null) {
+ throw new IllegalArgumentException("unknown world");
+ }
+
+ return new Location(world, NumberConversions.toDouble(args.get("x")), NumberConversions.toDouble(args.get("y")), NumberConversions.toDouble(args.get("z")), NumberConversions.toFloat(args.get("yaw")), NumberConversions.toFloat(args.get("pitch")));
+ }
}
diff --git a/src/main/java/org/bukkit/configuration/serialization/ConfigurationSerialization.java b/src/main/java/org/bukkit/configuration/serialization/ConfigurationSerialization.java
index 375297c6..e5ddef25 100644
--- a/src/main/java/org/bukkit/configuration/serialization/ConfigurationSerialization.java
+++ b/src/main/java/org/bukkit/configuration/serialization/ConfigurationSerialization.java
@@ -12,6 +12,7 @@ import java.util.logging.Logger;
import org.apache.commons.lang.Validate;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
+import org.bukkit.Location;
import org.bukkit.block.banner.Pattern;
import org.bukkit.configuration.Configuration;
import org.bukkit.inventory.ItemStack;
@@ -35,6 +36,7 @@ public class ConfigurationSerialization {
registerClass(PotionEffect.class);
registerClass(FireworkEffect.class);
registerClass(Pattern.class);
+ registerClass(Location.class);
}
protected ConfigurationSerialization(Class<? extends ConfigurationSerializable> clazz) {