Message formatting changes

+ All owners are shown with the info command
+ Removed the owner from formattedLocationString
+ Added dimensions to formattedLocationString
pull/2/head
Joey Hines 2020-08-16 13:25:43 -05:00
parent 0687caf051
commit f049ec304a
5 changed files with 54 additions and 24 deletions

View File

@ -1,14 +1,19 @@
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 GeoffreyPlayer owner;
private List<GeoffreyPlayer> owners;
private String dimension;
private String tunnelString = null;
private String link = null;
@ -17,9 +22,15 @@ public class GeoffreyLocation {
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();
this.link = locationJSON.get("link").getAsString();
JsonArray owners_json = locationJSON.getAsJsonArray("owner").getAsJsonArray();
this.owners= new ArrayList<GeoffreyPlayer>(owners_json.size());
for (JsonElement owner: owners_json) {
this.owners.add(new GeoffreyPlayer(owner.getAsJsonObject()));
}
JsonElement tunnelElement = locationJSON.get("tunnel");
@ -28,16 +39,16 @@ public class GeoffreyLocation {
}
}
public GeoffreyLocation(int xCoord, int zCoord, String locationName, GeoffreyPlayer owner, String dimension) {
public GeoffreyLocation(int xCoord, int zCoord, String locationName, List<GeoffreyPlayer> owners, String dimension) {
this.xCoord = xCoord;
this.zCoord = zCoord;
this.locationName = locationName;
this.owner = owner;
this.owners = owners;
this.dimension = dimension;
}
public String getPositionString() {
return "(x=" + xCoord + ",z=" + zCoord + ")";
return dimension + " (x=" + xCoord + ",z=" + zCoord + ")";
}
public String getFormattedLocationString() {
@ -47,13 +58,26 @@ public class GeoffreyLocation {
locationString += tunnelString + " ";
}
locationString += getPositionString() + " Owner: " + owner.getUsername();
locationString += getPositionString();
return locationString;
}
public String getInfoString() {
return ChatColor.BOLD + getFormattedLocationString().replace(" ", " " + ChatColor.BOLD) + ChatColor.RESET;
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() {
@ -68,8 +92,8 @@ public class GeoffreyLocation {
return locationName;
}
public GeoffreyPlayer getOwner() {
return owner;
public List<GeoffreyPlayer> getOwners() {
return owners;
}
public String getDimension() {

View File

@ -4,6 +4,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.LinkedList;
import java.util.List;
public class GeoffreyMarket extends GeoffreyLocation{
private LinkedList<GeoffreyLocation> shops;
@ -16,8 +17,8 @@ public class GeoffreyMarket extends GeoffreyLocation{
}
}
public GeoffreyMarket(int xCoord, int zCoord, String locationName, GeoffreyPlayer owner, String dimension, LinkedList<GeoffreyLocation> shops) {
super(xCoord, zCoord, locationName, owner, dimension);
public GeoffreyMarket(int xCoord, int zCoord, String locationName, List<GeoffreyPlayer> owners, String dimension, LinkedList<GeoffreyLocation> shops) {
super(xCoord, zCoord, locationName, owners, dimension);
this.shops = shops;
}

View File

@ -16,7 +16,7 @@ public class GeoffreyShop extends GeoffreyLocation{
public GeoffreyShop(JsonObject locationJSON) {
super(locationJSON);
items = new <GeoffreyItemListing>LinkedList();
items = new LinkedList<>();
if (!locationJSON.get("items").isJsonNull()) {
JsonArray itemsJSON = locationJSON.get("items").getAsJsonArray();
@ -28,12 +28,12 @@ public class GeoffreyShop extends GeoffreyLocation{
}
}
public GeoffreyShop(int xCoord, int zCoord, String locationName, GeoffreyPlayer owner, String dimension) {
super(xCoord, zCoord, locationName, owner, dimension);
items = new <GeoffreyItemListing>LinkedList();
public GeoffreyShop(int xCoord, int zCoord, String locationName, List<GeoffreyPlayer> owners, String dimension) {
super(xCoord, zCoord, locationName, owners, dimension);
items = new LinkedList<>();
}
public List getItems() {
public List<GeoffreyItemListing> getItems() {
return items;
}
@ -43,7 +43,7 @@ public class GeoffreyShop extends GeoffreyLocation{
infoString.append(super.getInfoString());
infoString.append("\nItems:");
for (GeoffreyItemListing item: Iterables.limit(items, 5)) {
for (GeoffreyItemListing item: Iterables.limit(items, 10)) {
infoString.append("\n");
infoString.append(item.getFormattedItemListing());
}

View File

@ -5,9 +5,10 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.LinkedList;
import java.util.List;
public class GeoffreyTown extends GeoffreyLocation {
private LinkedList<GeoffreyPlayer> residents;
private List<GeoffreyPlayer> residents;
public GeoffreyTown(JsonObject locationJSON) {
super(locationJSON);
@ -17,8 +18,8 @@ public class GeoffreyTown extends GeoffreyLocation {
}
}
public GeoffreyTown(int xCoord, int zCoord, String locationName, GeoffreyPlayer owner, String dimension, LinkedList <GeoffreyPlayer> residents) {
super(xCoord, zCoord, locationName, owner, dimension);
public GeoffreyTown(int xCoord, int zCoord, String locationName, List<GeoffreyPlayer> owners, String dimension, List <GeoffreyPlayer> residents) {
super(xCoord, zCoord, locationName, owners, dimension);
this.residents = residents;
}
@ -28,9 +29,13 @@ public class GeoffreyTown extends GeoffreyLocation {
locationString.append(super.getInfoString());
locationString.append("\nResidents: ");
int i = 0;
for (GeoffreyPlayer resident: Iterables.limit(residents, 5)) {
locationString.append("\n");
locationString.append(resident.getUsername());
i++;
if (i < residents.size()) {
locationString.append(", ");
}
}
return locationString.toString();