package com.zerohighdef.geoffrey.Models; import com.google.gson.JsonElement; import com.google.gson.JsonObject; public class GeoffreyLocation { private int xCoord; private int zCoord; private String locationName; private GeoffreyPlayer owner; private String dimension; private String tunnelString = null; public GeoffreyLocation(JsonObject locationJSON) { this.xCoord = locationJSON.get("x_coord").getAsInt(); this.zCoord = locationJSON.get("z_coord").getAsInt(); this.locationName = locationJSON.get("name").getAsString(); this.owner = new GeoffreyPlayer(locationJSON.getAsJsonArray("owner").getAsJsonArray().get(0).getAsJsonObject()); this.dimension = locationJSON.get("dimension").getAsString(); JsonElement tunnelElement = locationJSON.get("tunnel"); if (!tunnelElement.isJsonNull()) { this.tunnelString = tunnelElement.getAsString(); } } public GeoffreyLocation(int xCoord, int zCoord, String locationName, GeoffreyPlayer owner, String dimension) { this.xCoord = xCoord; this.zCoord = zCoord; this.locationName = locationName; this.owner = owner; this.dimension = dimension; } public String getPositionString() { return "(x=" + xCoord + ",z=" + zCoord + ")"; } public String getFormattedLocationString() { String locationString = locationName + " @ " + getPositionString() + " Owner: " + owner.getUsername(); if (tunnelString != null) { locationString += " Tunnel: " + tunnelString; } return locationString; } public int getxCoord() { return xCoord; } public int getzCoord() { return zCoord; } public String getLocationName() { return locationName; } public GeoffreyPlayer getOwner() { return owner; } public String getDimension() { return dimension; } public String getTunnel() { return tunnelString; } }