From f049ec304ad87ebbf7e8614c20f0f791dfe510a5 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 16 Aug 2020 13:25:43 -0500 Subject: [PATCH] Message formatting changes + All owners are shown with the info command + Removed the owner from formattedLocationString + Added dimensions to formattedLocationString --- .../geoffrey/Commands/AddResidentCommand.java | 2 +- .../geoffrey/Models/GeoffreyLocation.java | 42 +++++++++++++++---- .../geoffrey/Models/GeoffreyMarket.java | 5 ++- .../geoffrey/Models/GeoffreyShop.java | 14 +++---- .../geoffrey/Models/GeoffreyTown.java | 15 ++++--- 5 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java index 3b271d5..aba8611 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java @@ -54,7 +54,7 @@ public class AddResidentCommand extends GeoffreyCommand { CommandCallback(CommandSender sender, String newResidentName) { 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("LocationLookUpError", "You do not have a town by that name you ding dong goober."); this.newResidentName = newResidentName; diff --git a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java index 2c20b77..5b6e1aa 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java +++ b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java @@ -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 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(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 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 getOwners() { + return owners; } public String getDimension() { diff --git a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyMarket.java b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyMarket.java index 05e0c66..06f5b77 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyMarket.java +++ b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyMarket.java @@ -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 shops; @@ -16,8 +17,8 @@ public class GeoffreyMarket extends GeoffreyLocation{ } } - public GeoffreyMarket(int xCoord, int zCoord, String locationName, GeoffreyPlayer owner, String dimension, LinkedList shops) { - super(xCoord, zCoord, locationName, owner, dimension); + public GeoffreyMarket(int xCoord, int zCoord, String locationName, List owners, String dimension, LinkedList shops) { + super(xCoord, zCoord, locationName, owners, dimension); this.shops = shops; } diff --git a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyShop.java b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyShop.java index cb30e93..2bdb3ed 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyShop.java +++ b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyShop.java @@ -11,12 +11,12 @@ import java.util.List; public class GeoffreyShop extends GeoffreyLocation{ - private List items; + private List items; public GeoffreyShop(JsonObject locationJSON) { super(locationJSON); - items = new 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 LinkedList(); + public GeoffreyShop(int xCoord, int zCoord, String locationName, List owners, String dimension) { + super(xCoord, zCoord, locationName, owners, dimension); + items = new LinkedList<>(); } - public List getItems() { + public List 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()); } diff --git a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyTown.java b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyTown.java index 7a1a6a9..6e54516 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyTown.java +++ b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyTown.java @@ -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 residents; + private List 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 residents) { - super(xCoord, zCoord, locationName, owner, dimension); + public GeoffreyTown(int xCoord, int zCoord, String locationName, List owners, String dimension, List residents) { + super(xCoord, zCoord, locationName, owners, dimension); this.residents = residents; } @@ -26,11 +27,15 @@ public class GeoffreyTown extends GeoffreyLocation { public String getInfoString() { StringBuilder locationString = new StringBuilder(); locationString.append(super.getInfoString()); - locationString.append("\nResidents:"); + 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();