Program: 2025
Project: 2025
Buggy source:
private void handleNPCItemClicked(int slot,PlayerInventory npcInv){
  npcInv.setItem(slot,previousNPCInv.getItem(slot));
  ItemStack i=npcInv.getItem(slot);
  if (!(npc.getTraderNPC().isStocked(i.getTypeId(),i.getData(),false))) {
    player.sendMessage(StringUtils.yellowify(i.getType().name(),ChatColor.RED) + "String_Node_Str");
    return;
  }
  Stockable stockable=npc.getTraderNPC().getStockable(i.getTypeId(),false);
  ItemStack buying=stockable.getStocking();
  if (previousNPCClickedSlot != slot) {
    previousNPCClickedSlot=slot;
    player.sendMessage(ChatColor.AQUA + "String_Node_Str" + MessageUtils.getStockableMessage(stockable,ChatColor.AQUA)+ "String_Node_Str");
    return;
  }
  previousNPCClickedSlot=slot;
  int amount=npcInv.getItem(slot).getAmount();
  if (amount - buying.getAmount() <= 0) {
    player.sendMessage(ChatColor.RED + "String_Node_Str" + StringUtils.yellowify(buying.getAmount() + "String_Node_Str" + buying.getType().name(),ChatColor.RED)+ "String_Node_Str");
    return;
  }
  if (!EconomyHandler.canBuy(new Payment(stockable.getPrice()),player)) {
    player.sendMessage(ChatColor.RED + "String_Node_Str" + StringUtils.yellowify(buying.getAmount() + "String_Node_Str" + buying.getType().name(),ChatColor.RED)+ "String_Node_Str");
    return;
  }
  HashMap<Integer,ItemStack> unbought=player.getInventory().addItem(buying);
  if (unbought.size() >= 1) {
    player.getInventory().setContents(previousPlayerInv.getContents());
    player.sendMessage(ChatColor.RED + "String_Node_Str" + StringUtils.yellowify(buying.getAmount() + "String_Node_Str" + buying.getType().name(),ChatColor.RED)+ "String_Node_Str");
    return;
  }
  EconomyHandler.pay(new Payment(stockable.getPrice()),player);
  EconomyHandler.pay(new Payment(stockable.getStocking(),stockable.getPrice().isiConomy()),npc);
  player.sendMessage(ChatColor.GREEN + "String_Node_Str");
}

Fixed version (ground truth):
private void handleNPCItemClicked(int slot,PlayerInventory npcInv){
  npcInv.setItem(slot,previousNPCInv.getItem(slot));
  ItemStack i=npcInv.getItem(slot);
  if (!(npc.getTraderNPC().isStocked(i.getTypeId(),i.getData(),false))) {
    player.sendMessage(StringUtils.yellowify(i.getType().name(),ChatColor.RED) + "String_Node_Str");
    return;
  }
  Stockable stockable=npc.getTraderNPC().getStockable(i.getTypeId(),false);
  ItemStack buying=stockable.getStocking();
  if (previousNPCClickedSlot != slot) {
    previousNPCClickedSlot=slot;
    player.sendMessage(ChatColor.AQUA + "String_Node_Str" + MessageUtils.getStockableMessage(stockable,ChatColor.AQUA)+ "String_Node_Str");
    return;
  }
  previousNPCClickedSlot=slot;
  int amount=npcInv.getItem(slot).getAmount();
  if (amount - buying.getAmount() <= 0) {
    player.sendMessage(ChatColor.RED + "String_Node_Str" + StringUtils.yellowify(buying.getAmount() + "String_Node_Str" + buying.getType().name(),ChatColor.RED)+ "String_Node_Str");
    return;
  }
  if (!EconomyHandler.canBuy(new Payment(stockable.getPrice()),player)) {
    player.sendMessage(ChatColor.RED + "String_Node_Str" + StringUtils.yellowify(buying.getAmount() + "String_Node_Str" + buying.getType().name(),ChatColor.RED)+ "String_Node_Str");
    return;
  }
  HashMap<Integer,ItemStack> unbought=player.getInventory().addItem(buying);
  if (unbought.size() >= 1) {
    player.getInventory().setContents(previousPlayerInv.getContents());
    player.sendMessage(ChatColor.RED + "String_Node_Str" + StringUtils.yellowify(buying.getAmount() + "String_Node_Str" + buying.getType().name(),ChatColor.RED)+ "String_Node_Str");
    return;
  }
  HashMap<Integer,ItemStack> ungiven=npc.getPlayer().getInventory().addItem(stockable.getStocking());
  if (ungiven.size() >= 1) {
    npc.getInventory().setContents(previousNPCInv.getContents());
    player.getInventory().setContents(previousPlayerInv.getContents());
    player.sendMessage(ChatColor.RED + "String_Node_Str" + StringUtils.yellowify(stockable.getStocking().getAmount() + "String_Node_Str" + stockable.getStocking().getType().name(),ChatColor.RED)+ "String_Node_Str");
    return;
  }
  EconomyHandler.pay(new Payment(stockable.getPrice()),player);
  EconomyHandler.pay(new Payment(stockable.getStocking(),stockable.getPrice().isiConomy()),npc);
  player.sendMessage(ChatColor.GREEN + "String_Node_Str");
}