diff --git a/src/main/java/com/massivecraft/factions/P.java b/src/main/java/com/massivecraft/factions/P.java index fa12f84b..376e7d9f 100644 --- a/src/main/java/com/massivecraft/factions/P.java +++ b/src/main/java/com/massivecraft/factions/P.java @@ -394,6 +394,7 @@ public class P extends MPlugin { .registerTypeAdapter(LazyLocation.class, new MyLocationTypeAdapter()) .registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter()) .registerTypeAdapter(Inventory.class, new InventoryTypeAdapter()) + .registerTypeAdapter(Location.class, new LocationTypeAdapter()) .registerTypeAdapterFactory(EnumTypeAdapter.ENUM_FACTORY); } diff --git a/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java b/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java new file mode 100644 index 00000000..a4c8401f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java @@ -0,0 +1,34 @@ +package com.massivecraft.factions.util; + +import com.google.gson.*; +import org.bukkit.Bukkit; +import org.bukkit.Location; + +import java.lang.reflect.Type; + +public class LocationTypeAdapter implements JsonSerializer, JsonDeserializer { + + @Override + public JsonElement serialize(Location location, Type type, JsonSerializationContext jsonSerializationContext) { + + JsonObject object = new JsonObject(); + object.add("x", new JsonPrimitive(location.getX())); + object.add("y", new JsonPrimitive(location.getY())); + object.add("z", new JsonPrimitive(location.getZ())); + object.add("world", new JsonPrimitive(location.getWorld().toString())); + return object; + } + + + @Override + public Location deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { + JsonObject object = jsonElement.getAsJsonObject(); + return new Location(Bukkit.getWorld(object.get("world").getAsString()), + object.get("x").getAsDouble(), + object.get("y").getAsDouble(), + object.get("z").getAsDouble()); + + } + + +}