package com.zerohighdef.geoffrey.Models; import com.google.common.collect.Iterables; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import org.bukkit.ChatColor; import java.util.ArrayList; import java.util.List; public class GeoffreyLocation { private int xCoord; private int zCoord; private String locationName; private List owners; private String dimension; private String tunnelString = null; private String link = 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.dimension = locationJSON.get("dimension").getAsString(); this.link = locationJSON.get("link").getAsString(); JsonArray owners_json = locationJSON.getAsJsonArray("owner").getAsJsonArray(); this.owners= new ArrayList(owners_json.size()); for (JsonElement owner: owners_json) { this.owners.add(new GeoffreyPlayer(owner.getAsJsonObject())); } JsonElement tunnelElement = locationJSON.get("tunnel"); if (!tunnelElement.isJsonNull()) { this.tunnelString = tunnelElement.getAsString(); } } public GeoffreyLocation(int xCoord, int zCoord, String locationName, List owners, String dimension) { this.xCoord = xCoord; this.zCoord = zCoord; this.locationName = locationName; this.owners = owners; this.dimension = dimension; } public String getPositionString() { return dimension + " (x=" + xCoord + ",z=" + zCoord + ")"; } public String getFormattedLocationString() { String locationString = locationName + " @ "; if (tunnelString != null) { locationString += tunnelString + " "; } locationString += getPositionString(); return locationString; } public String getInfoString() { StringBuilder infoString = new StringBuilder(); infoString.append(ChatColor.BOLD).append(getFormattedLocationString().replace(" ", " " + ChatColor.BOLD)); infoString.append(ChatColor.RESET); infoString.append("\nOwners: "); int i = 0; for (GeoffreyPlayer owner: Iterables.limit(owners, 5)) { infoString.append(owner.getUsername()).append(","); i++; if (i < owners.size()) { infoString.append(","); } } return infoString.toString(); } public int getxCoord() { return xCoord; } public int getzCoord() { return zCoord; } public String getLocationName() { return locationName; } public List getOwners() { return owners; } public String getDimension() { return dimension; } public String getTunnel() { return tunnelString; } public String getLink() { return link; } }