Example #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.");
 }
Example #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.");
 }
Example #3
0
 private void sendNoMoneyMessage(ItemStack stocking, boolean selling) {
   selling = !selling;
   String start = "The trader doesn't";
   if (selling) {
     start = "You don't";
   }
   player.sendMessage(
       ChatColor.RED
           + start
           + " have enough money available to buy "
           + MessageUtils.getStackString(stocking)
           + ".");
 }
Example #4
0
 private Stockable getStockable(ItemStack item, String keyword, boolean selling) {
   // durability needs to be reset to 0 for tools / weapons / armor
   short durability = item.getDurability();
   if (isTool(item.getTypeId())) {
     durability = 0;
   }
   TraderNPC trader = npc.getToggleable("trader");
   if (!trader.isStocked(item.getTypeId(), durability, selling)) {
     player.sendMessage(
         StringUtils.wrap(MessageUtils.getItemName(item.getTypeId()), ChatColor.RED)
             + " isn't being "
             + keyword
             + " here.");
     return null;
   }
   return trader.getStockable(item.getTypeId(), durability, selling);
 }
Example #5
0
 private void sendStockableMessage(Stockable stockable) {
   String[] message = MessageUtils.getStockableMessage(stockable, ChatColor.AQUA).split("for");
   player.sendMessage(ChatColor.AQUA + "Item: " + message[0].trim());
   player.sendMessage(ChatColor.AQUA + "Price: " + message[1].trim());
   player.sendMessage(ChatColor.GOLD + "Click to confirm.");
 }