58 lines
1.6 KiB
Java
58 lines
1.6 KiB
Java
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 java.awt.event.ItemListener;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
public class GeoffreyShop extends GeoffreyLocation{
|
|
|
|
private List<GeoffreyItemListing> items;
|
|
|
|
public GeoffreyShop(JsonObject locationJSON) {
|
|
super(locationJSON);
|
|
|
|
items = new LinkedList<>();
|
|
if (!locationJSON.get("items").isJsonNull()) {
|
|
JsonArray itemsJSON = locationJSON.get("items").getAsJsonArray();
|
|
|
|
for (JsonElement element: itemsJSON) {
|
|
JsonObject item = element.getAsJsonObject();
|
|
|
|
items.add(new GeoffreyItemListing(item));
|
|
}
|
|
}
|
|
}
|
|
|
|
public GeoffreyShop(int xCoord, int zCoord, String locationName, List<GeoffreyPlayer> owners, String dimension) {
|
|
super(xCoord, zCoord, locationName, owners, dimension);
|
|
items = new LinkedList<>();
|
|
}
|
|
|
|
public List<GeoffreyItemListing> getItems() {
|
|
return items;
|
|
}
|
|
|
|
@Override
|
|
public String getInfoString() {
|
|
StringBuilder infoString = new StringBuilder();
|
|
infoString.append(super.getInfoString());
|
|
infoString.append("\nItems:");
|
|
|
|
for (GeoffreyItemListing item: Iterables.limit(items, 10)) {
|
|
infoString.append("\n");
|
|
infoString.append(item.getFormattedItemListing());
|
|
}
|
|
|
|
return infoString.toString();
|
|
}
|
|
|
|
public GeoffreyItemListing getFirstItem() {
|
|
return items.get(0);
|
|
}
|
|
}
|