Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.bukkit.configuration.serialization.ConfigurationSerializable;
- import org.bukkit.configuration.serialization.SerializableAs;
- import org.bukkit.inventory.ItemStack;
- @SerializableAs("ChimneyShopData")
- public class ShopData implements ConfigurationSerializable {
- private String player;
- private List<ShopItem> saleItems;
- private boolean adminShop;
- public ShopData(String owner) {
- player = owner;
- saleItems = new ArrayList<ShopItem>();
- adminShop = false;
- }
- @SerializableAs("ChimneyShopItem")
- public class ShopItem implements ConfigurationSerializable {
- public ItemStack item;
- public int price;
- public int quantity;
- public ShopItem(ItemStack item, int cost, int quant) {
- this.item = item;
- price = cost;
- quantity = quant;
- }
- public ShopItem(Map<String, Object> data) {
- item = (ItemStack) data.get("item");
- price = (Integer) data.get("price");
- quantity = (Integer) data.get("amount");
- }
- @Override
- public Map<String, Object> serialize() {
- Map<String, Object> ret = new HashMap<String, Object>();
- ret.put("item", item);
- ret.put("price", price);
- ret.put("amount", quantity);
- return ret;
- }
- }
- @Override
- public Map<String, Object> serialize() {
- Map<String, Object> ret = new HashMap<String, Object>();
- ret.put("owner", player);
- ret.put("inf", adminShop);
- ret.put("items", saleItems.toArray());
- return ret;
- }
- public static ShopData deserialize(Map<String, Object> data) {
- ShopData ret = new ShopData((String) data.get("owner"));
- ret.adminShop = (Boolean) data.get("inf");
- List<?> items = (List<?>) data.get("items");
- for (Object o : items) {
- if (o instanceof ShopItem) {
- ret.saleItems.add((ShopItem) o);
- }
- }
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement