Advertisement
riking

Untitled

Aug 3rd, 2013
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5.  
  6. import org.bukkit.configuration.serialization.ConfigurationSerializable;
  7. import org.bukkit.configuration.serialization.SerializableAs;
  8. import org.bukkit.inventory.ItemStack;
  9.  
  10. @SerializableAs("ChimneyShopData")
  11. public class ShopData implements ConfigurationSerializable {
  12.     private String player;
  13.     private List<ShopItem> saleItems;
  14.     private boolean adminShop;
  15.  
  16.     public ShopData(String owner) {
  17.         player = owner;
  18.         saleItems = new ArrayList<ShopItem>();
  19.         adminShop = false;
  20.     }
  21.  
  22.     @SerializableAs("ChimneyShopItem")
  23.     public class ShopItem implements ConfigurationSerializable {
  24.         public ItemStack item;
  25.         public int price;
  26.         public int quantity;
  27.  
  28.         public ShopItem(ItemStack item, int cost, int quant) {
  29.             this.item = item;
  30.             price = cost;
  31.             quantity = quant;
  32.         }
  33.  
  34.         public ShopItem(Map<String, Object> data) {
  35.             item = (ItemStack) data.get("item");
  36.             price = (Integer) data.get("price");
  37.             quantity = (Integer) data.get("amount");
  38.         }
  39.  
  40.         @Override
  41.         public Map<String, Object> serialize() {
  42.             Map<String, Object> ret = new HashMap<String, Object>();
  43.             ret.put("item", item);
  44.             ret.put("price", price);
  45.             ret.put("amount", quantity);
  46.             return ret;
  47.         }
  48.     }
  49.  
  50.     @Override
  51.     public Map<String, Object> serialize() {
  52.         Map<String, Object> ret = new HashMap<String, Object>();
  53.         ret.put("owner", player);
  54.         ret.put("inf", adminShop);
  55.         ret.put("items", saleItems.toArray());
  56.         return ret;
  57.     }
  58.  
  59.     public static ShopData deserialize(Map<String, Object> data) {
  60.         ShopData ret = new ShopData((String) data.get("owner"));
  61.         ret.adminShop = (Boolean) data.get("inf");
  62.         List<?> items = (List<?>) data.get("items");
  63.         for (Object o : items) {
  64.             if (o instanceof ShopItem) {
  65.                 ret.saleItems.add((ShopItem) o);
  66.             }
  67.         }
  68.         return ret;
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement