Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package io.github.hsyyid.adminshop.utils;
- import java.io.IOException;
- import org.spongepowered.api.world.Location;
- import com.google.gson.TypeAdapter;
- import com.google.gson.stream.JsonReader;
- import com.google.gson.stream.JsonToken;
- import com.google.gson.stream.JsonWriter;
- public class LocationAdapter extends TypeAdapter<Location>
- {
- @Override
- public void write(JsonWriter out, Location location) throws IOException
- {
- if (location == null)
- {
- out.nullValue();
- return;
- }
- out.beginObject();
- out.name("x");
- out.value(location.getX());
- out.name("y");
- out.value(location.getY());
- out.name("z");
- out.value(location.getZ());
- out.endObject();
- }
- @Override
- public Location read(JsonReader in) throws IOException
- {
- if (in.peek() == JsonToken.NULL)
- {
- return null;
- }
- in.beginObject();
- in.nextName();
- double x = in.nextDouble();
- in.nextName();
- double y = in.nextDouble();
- in.nextName();
- double z = in.nextDouble();
- in.endObject();
- Location location = new Location(null, x, y, z);
- return location;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement