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

@ -54,7 +54,7 @@ public class AddResidentCommand extends GeoffreyCommand {
CommandCallback(CommandSender sender, String newResidentName) { CommandCallback(CommandSender sender, String newResidentName) {
super(sender); super(sender);
errors.put("ResidentNotFoundError", "Ain't no one in this darn database named" + newResidentName + "you goob"); errors.put("ResidentNotFoundError", "Ain't no one in this darn database named " + newResidentName + " you goob");
errors.put("IsResidentError", newResidentName + " is already a resident, stop having amosia."); errors.put("IsResidentError", newResidentName + " is already a resident, stop having amosia.");
errors.put("LocationLookUpError", "You do not have a town by that name you ding dong goober."); errors.put("LocationLookUpError", "You do not have a town by that name you ding dong goober.");
this.newResidentName = newResidentName; this.newResidentName = newResidentName;

View File

@ -1,14 +1,19 @@
package com.zerohighdef.geoffrey.Models; 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.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import java.util.ArrayList;
import java.util.List;
public class GeoffreyLocation { public class GeoffreyLocation {
private int xCoord; private int xCoord;
private int zCoord; private int zCoord;
private String locationName; private String locationName;
private GeoffreyPlayer owner; private List<GeoffreyPlayer> owners;
private String dimension; private String dimension;
private String tunnelString = null; private String tunnelString = null;
private String link = null; private String link = null;
@ -17,9 +22,15 @@ public class GeoffreyLocation {
this.xCoord = locationJSON.get("x_coord").getAsInt(); this.xCoord = locationJSON.get("x_coord").getAsInt();
this.zCoord = locationJSON.get("z_coord").getAsInt(); this.zCoord = locationJSON.get("z_coord").getAsInt();
this.locationName = locationJSON.get("name").getAsString(); this.locationName = locationJSON.get("name").getAsString();
this.owner = new GeoffreyPlayer(locationJSON.getAsJsonArray("owner").getAsJsonArray().get(0).getAsJsonObject());
this.dimension = locationJSON.get("dimension").getAsString(); this.dimension = locationJSON.get("dimension").getAsString();
this.link = locationJSON.get("link").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"); 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.xCoord = xCoord;
this.zCoord = zCoord; this.zCoord = zCoord;
this.locationName = locationName; this.locationName = locationName;
this.owner = owner; this.owners = owners;
this.dimension = dimension; this.dimension = dimension;
} }
public String getPositionString() { public String getPositionString() {
return "(x=" + xCoord + ",z=" + zCoord + ")"; return dimension + " (x=" + xCoord + ",z=" + zCoord + ")";
} }
public String getFormattedLocationString() { public String getFormattedLocationString() {
@ -47,13 +58,26 @@ public class GeoffreyLocation {
locationString += tunnelString + " "; locationString += tunnelString + " ";
} }
locationString += getPositionString() + " Owner: " + owner.getUsername(); locationString += getPositionString();
return locationString; return locationString;
} }
public String getInfoString() { 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() { public int getxCoord() {
@ -68,8 +92,8 @@ public class GeoffreyLocation {
return locationName; return locationName;
} }
public GeoffreyPlayer getOwner() { public List<GeoffreyPlayer> getOwners() {
return owner; return owners;
} }
public String getDimension() { public String getDimension() {

View File

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

View File

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

View File

@ -5,9 +5,10 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
public class GeoffreyTown extends GeoffreyLocation { public class GeoffreyTown extends GeoffreyLocation {
private LinkedList<GeoffreyPlayer> residents; private List<GeoffreyPlayer> residents;
public GeoffreyTown(JsonObject locationJSON) { public GeoffreyTown(JsonObject locationJSON) {
super(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) { public GeoffreyTown(int xCoord, int zCoord, String locationName, List<GeoffreyPlayer> owners, String dimension, List <GeoffreyPlayer> residents) {
super(xCoord, zCoord, locationName, owner, dimension); super(xCoord, zCoord, locationName, owners, dimension);
this.residents = residents; this.residents = residents;
} }
@ -26,11 +27,15 @@ public class GeoffreyTown extends GeoffreyLocation {
public String getInfoString() { public String getInfoString() {
StringBuilder locationString = new StringBuilder(); StringBuilder locationString = new StringBuilder();
locationString.append(super.getInfoString()); locationString.append(super.getInfoString());
locationString.append("\nResidents:"); locationString.append("\nResidents: ");
int i = 0;
for (GeoffreyPlayer resident: Iterables.limit(residents, 5)) { for (GeoffreyPlayer resident: Iterables.limit(residents, 5)) {
locationString.append("\n");
locationString.append(resident.getUsername()); locationString.append(resident.getUsername());
i++;
if (i < residents.size()) {
locationString.append(", ");
}
} }
return locationString.toString(); return locationString.toString();