Created a location type adapter, and fixed f checkpoint issues
This commit is contained in:
parent
f1a42749da
commit
934169bf6a
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<Location>, JsonDeserializer<Location> {
|
||||
|
||||
@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());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user