package de.philworld.bukkit.compassex;

import java.util.HashMap;
import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.util.Vector;

public class OwnedLocation implements ConfigurationSerializable {

	private String id;
	private String playerName;
	private Location location;

	public OwnedLocation(String id, String playerName, Location location) {
		this.id = id;
		this.playerName = playerName;
		this.location = location;
	}
	
	public OwnedLocation(Map<String, Object> map) {
		this.id = map.get("id").toString();
		this.playerName = map.get("playerName").toString();
		
		Map<?, ?> locationSection = (Map<?, ?>) map.get("location");
		Vector vec = (Vector) locationSection.get("vector");
		String world = locationSection.get("world").toString();
		
		this.location = new Location(Bukkit.getServer().getWorld(world), vec.getX(), vec.getY(), vec.getZ());
		
	}
	
	public static OwnedLocation deserialize(Map<String, Object> map) {
		return new OwnedLocation(map);
	}
	
	@Override
	public Map<String, Object> serialize() {
		HashMap<String, Object> result = new HashMap<String, Object>();
		
		result.put("id", id);
		result.put("playerName", playerName);
		
		HashMap<String, Object> locationSection = new HashMap<String, Object>();
		locationSection.put("vector", location.toVector());
		locationSection.put("world", location.getWorld().getName());
		
		result.put("location", locationSection);
		
		return result;
	}

	/**
	 * @return the playerName
	 */
	public String getPlayerName() {
		return playerName;
	}

	/**
	 * @param playerName the playerName to set
	 */
	public void setPlayerName(String playerName) {
		this.playerName = playerName;
	}

	/**
	 * @return the location
	 */
	public Location getLocation() {
		return location;
	}

	/**
	 * @param location the location to set
	 */
	public void setLocation(Location location) {
		this.location = location;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

}

@@ -313,24 +313,30 @@
 %7B%0A%0A%09private 
+final 
 String id;%0A%09
@@ -343,16 +343,22 @@
 private 
+final 
 String p
@@ -377,16 +377,22 @@
 private 
+final 
 Location
@@ -551,25 +551,24 @@
 ocation;%0A%09%7D%0A
-%09
 %0A%09public Own
@@ -697,18 +697,16 @@
 ring();%0A
-%09%09
 %0A%09%09Map%3C?
@@ -874,18 +874,16 @@
 ring();%0A
-%09%09
 %0A%09%09this.
@@ -941,17 +941,21 @@
 (world),
- 
+%0A%09%09%09%09
 vec.getX
@@ -987,15 +987,11 @@
 ));%0A
-%09%09%0A
 %09%7D%0A
-%09
 %0A%09pu
@@ -1091,17 +1091,16 @@
 ap);%0A%09%7D%0A
-%09
 %0A%09@Overr
@@ -1211,18 +1211,16 @@
 ect%3E();%0A
-%09%09
 %0A%09%09resul
@@ -1276,18 +1276,16 @@
 rName);%0A
-%09%09
 %0A%09%09HashM
@@ -1469,18 +1469,16 @@
 ame());%0A
-%09%09
 %0A%09%09resul
@@ -1513,18 +1513,16 @@
 ction);%0A
-%09%09
 %0A%09%09retur
@@ -1540,43 +1540,48 @@
 %7D%0A%0A%09
-/**%0A%09 * @return the playerName%0A%09 */
+public String getId() %7B%0A%09%09return id;%0A%09%7D%0A
 %0A%09pu
@@ -1640,429 +1640,57 @@
 %7D%0A%0A%09
-/**%0A%09 * @param playerName the playerName to set%0A%09 */%0A%09public void setPlayerName(String playerName) %7B%0A%09%09this.playerName = playerName;%0A%09%7D%0A%0A%09/**%0A%09 * @return the location%0A%09 */%0A%09public Location getLocation() %7B%0A%09%09return location;%0A%09%7D%0A%0A%09/**%0A%09 * @param location the location to set%0A%09 */%0A%09public void setLocation(Location location) %7B%0A%09%09this.location = location;%0A%09%7D%0A%0A%09/**%0A%09 * @return the id%0A%09 */%0A%09public String getId() %7B%0A%09%09return id
+public Location getLocation() %7B%0A%09%09return location
 ;%0A%09%7D

Make OwnedLocation immutable