Beispiel #1
0
 @SuppressWarnings("deprecation")
 private void handlePlayerClick(int slot, PlayerInventory playerInv) {
   playerInv.setItem(slot, previousPlayerInv.getItem(slot));
   Stockable stockable = getStockable(playerInv.getItem(slot), "bought", true);
   if (stockable == null) {
     return;
   }
   if (prevPlayerSlot != slot) {
     prevPlayerSlot = slot;
     sendStockableMessage(stockable);
     return;
   }
   prevPlayerSlot = slot;
   prevTraderSlot = -1;
   if (checkMiscellaneous(playerInv, stockable, false)) {
     return;
   }
   ItemStack selling = stockable.getStocking().clone();
   if (mode != Mode.INFINITE) {
     EconomyHandler.pay(new Payment(stockable.getPrice()), npc, -1);
   }
   EconomyHandler.pay(new Payment(selling), player, slot);
   HashMap<Integer, ItemStack> unsold = new HashMap<Integer, ItemStack>();
   if (mode != Mode.INFINITE) {
     unsold = npc.getInventory().addItem(selling);
   }
   if (unsold.size() >= 1) {
     rewind();
     player.sendMessage(
         ChatColor.RED
             + "Not enough room available to add "
             + MessageUtils.getStackString(selling, ChatColor.RED)
             + " to the trader's stock.");
     return;
   }
   if (!stockable.isEconPlugin()) {
     ItemStack temp = stockable.getPrice().getItemStack().clone();
     unsold = player.getInventory().addItem(temp);
     if (unsold.size() >= 1) {
       rewind();
       player.sendMessage(
           ChatColor.RED
               + "Not enough room in your inventory to add "
               + MessageUtils.getStackString(stockable.getPrice().getItemStack(), ChatColor.RED)
               + ".");
       return;
     }
   } else {
     double price = stockable.getPrice().getPrice();
     ServerEconomyInterface.add(player.getName(), price);
   }
   npc.getPlayer().updateInventory();
   player.updateInventory();
   player.sendMessage(ChatColor.GREEN + "Transaction successful.");
 }
Beispiel #2
0
 @SuppressWarnings("deprecation")
 private void handleTraderClick(int slot, PlayerInventory npcInv) {
   npcInv.setItem(slot, previousTraderInv.getItem(slot));
   Stockable stockable = getStockable(npcInv.getItem(slot), "sold", false);
   if (stockable == null) {
     return;
   }
   if (prevTraderSlot != slot) {
     prevTraderSlot = slot;
     sendStockableMessage(stockable);
     return;
   }
   prevTraderSlot = slot;
   prevPlayerSlot = -1;
   if (checkMiscellaneous(npcInv, stockable, true)) {
     return;
   }
   // /trader sell 1:1 1:5
   // stocking is 1 stone
   // price is 5 stone
   ItemStack buying = stockable.getStocking().clone();
   EconomyHandler.pay(new Payment(stockable.getPrice()), player, -1);
   if (mode != Mode.INFINITE) {
     EconomyHandler.pay(new Payment(buying), npc, slot);
   }
   HashMap<Integer, ItemStack> unbought = player.getInventory().addItem(buying);
   if (unbought.size() >= 1) {
     rewind();
     player.sendMessage(
         ChatColor.RED
             + "Not enough room in your inventory to add "
             + MessageUtils.getStackString(buying, ChatColor.RED)
             + ".");
     return;
   }
   if (!stockable.isEconPlugin() && mode != Mode.INFINITE) {
     ItemStack temp = stockable.getPrice().getItemStack().clone();
     unbought = npc.getInventory().addItem(temp);
     if (unbought.size() >= 1) {
       rewind();
       player.sendMessage(
           ChatColor.RED
               + "Not enough room in the npc's inventory to add "
               + MessageUtils.getStackString(stockable.getPrice().getItemStack(), ChatColor.RED)
               + ".");
       return;
     }
   } else {
     double price = stockable.getPrice().getPrice();
     npc.setBalance(npc.getBalance() + price);
   }
   npc.getPlayer().updateInventory();
   player.updateInventory();
   player.sendMessage(ChatColor.GREEN + "Transaction successful.");
 }
Beispiel #3
0
 private boolean checkMiscellaneous(PlayerInventory inv, Stockable stockable, boolean buying) {
   ItemStack stocking = stockable.getStocking();
   if (buying) {
     if (!EconomyHandler.canBuy(new Payment(stocking), npc)) {
       sendNoMoneyMessage(stocking, true);
       return true;
     }
     if (!EconomyHandler.canBuy(new Payment(stockable.getPrice()), player)) {
       sendNoMoneyMessage(stocking, false);
       return true;
     }
   } else {
     if (!EconomyHandler.canBuy(new Payment(stocking), player)) {
       sendNoMoneyMessage(stocking, true);
       return true;
     }
     if (!EconomyHandler.canBuy(new Payment(stockable.getPrice()), npc)) {
       sendNoMoneyMessage(stocking, false);
       return true;
     }
   }
   return false;
 }