package com.zerohighdef.geoffrey.Models; import com.google.common.collect.Iterables; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import java.util.LinkedList; import java.util.List; public class GeoffreyTown extends GeoffreyLocation { private List residents; public GeoffreyTown(JsonObject locationJSON) { super(locationJSON); this.residents = new LinkedList<>(); for (JsonElement json : locationJSON.get("residents").getAsJsonArray()) { this.residents.add(new GeoffreyPlayer(json.getAsJsonObject())); } } public GeoffreyTown(int xCoord, int zCoord, String locationName, List owners, String dimension, List residents) { super(xCoord, zCoord, locationName, owners, dimension); this.residents = residents; } @Override public String getInfoString() { StringBuilder locationString = new StringBuilder(); locationString.append(super.getInfoString()); locationString.append("\nResidents: "); int i = 0; for (GeoffreyPlayer resident: Iterables.limit(residents, 5)) { locationString.append(resident.getUsername()); i++; if (i < residents.size()) { locationString.append(", "); } } return locationString.toString(); } }