コード例 #1
0
 @Override
 protected void saveEditor(Inventory inventory, Player player) {
   for (int i = 0; i < 8; i++) {
     ItemStack item = inventory.getItem(i);
     if (item != null && item.getType() != Material.AIR) {
       ItemStack cost1 = null, cost2 = null;
       ItemStack item1 = inventory.getItem(i + 9);
       ItemStack item2 = inventory.getItem(i + 18);
       if (item1 != null && item1.getType() != Material.AIR) {
         cost1 = item1;
         if (item2 != null && item2.getType() != Material.AIR) {
           cost2 = item2;
         }
       } else if (item2 != null && item2.getType() != Material.AIR) {
         cost1 = item2;
       }
       if (cost1 != null) {
         Cost cost = new Cost();
         cost.amount = item.getAmount();
         cost.item1 = cost1;
         cost.item2 = cost2;
         ItemStack saleItem = item.clone();
         saleItem.setAmount(1);
         ((TradingPlayerShopkeeper) shopkeeper).costs.put(saleItem, cost);
       } else {
         ItemStack saleItem = item.clone();
         saleItem.setAmount(1);
         ((TradingPlayerShopkeeper) shopkeeper).costs.remove(saleItem);
       }
     }
   }
   ((TradingPlayerShopkeeper) shopkeeper).clickedItem = null;
 }
コード例 #2
0
 @Override
 protected void load(ConfigurationSection config) {
   super.load(config);
   costs = new HashMap<ItemStack, Cost>();
   ConfigurationSection costsSection = config.getConfigurationSection("costs");
   if (costsSection != null) {
     for (String key : costsSection.getKeys(false)) {
       ConfigurationSection itemSection = costsSection.getConfigurationSection(key);
       ItemStack item = itemSection.getItemStack("item");
       if (itemSection.contains("attributes")) {
         String attr = itemSection.getString("attributes");
         if (attr != null && !attr.isEmpty()) {
           item = NMSManager.getProvider().loadItemAttributesFromString(item, attr);
         }
       }
       Cost cost = new Cost();
       cost.amount = itemSection.getInt("amount");
       cost.item1 = itemSection.getItemStack("item1");
       cost.item2 = itemSection.getItemStack("item2");
       costs.put(item, cost);
     }
   }
 }