@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;
 }
 @Override
 protected void onInventoryClick(InventoryClickEvent event, Player player) {
   event.setCancelled(true);
   final int slot = event.getRawSlot();
   if (slot >= 0 && slot <= 7) {
     // handle changing sell stack size
     ItemStack item = event.getCurrentItem();
     if (item != null && item.getType() != Material.AIR) {
       int amount = item.getAmount();
       amount = this.getNewAmountAfterEditorClick(event, amount);
       if (amount <= 0) amount = 1;
       if (amount > item.getMaxStackSize()) amount = item.getMaxStackSize();
       item.setAmount(amount);
     }
   } else if ((slot >= 9 && slot <= 16) || (slot >= 18 && slot <= 25)) {
     if (((TradingPlayerShopkeeper) shopkeeper).clickedItem != null) {
       // placing item
       final Inventory inventory = event.getInventory();
       Bukkit.getScheduler()
           .runTaskLater(
               ShopkeepersPlugin.getInstance(),
               new Runnable() {
                 public void run() {
                   inventory.setItem(slot, ((TradingPlayerShopkeeper) shopkeeper).clickedItem);
                   ((TradingPlayerShopkeeper) shopkeeper).clickedItem = null;
                 }
               },
               1);
     } else {
       // changing stack size
       ItemStack item = event.getCurrentItem();
       if (item != null && item.getType() != Material.AIR) {
         int amount = item.getAmount();
         amount = this.getNewAmountAfterEditorClick(event, amount);
         if (amount <= 0) {
           event.getInventory().setItem(slot, null);
         } else {
           if (amount > item.getMaxStackSize()) amount = item.getMaxStackSize();
           item.setAmount(amount);
         }
       }
     }
   } else if (slot >= 27) {
     // clicking in player inventory
     if (event.isShiftClick() || !event.isLeftClick()) {
       return;
     }
     ItemStack cursor = event.getCursor();
     if (cursor != null && cursor.getType() != Material.AIR) {
       return;
     }
     ItemStack current = event.getCurrentItem();
     if (current != null && current.getType() != Material.AIR) {
       ((TradingPlayerShopkeeper) shopkeeper).clickedItem = current.clone();
       ((TradingPlayerShopkeeper) shopkeeper).clickedItem.setAmount(1);
     }
   } else {
     super.onInventoryClick(event, player);
   }
 }