Program: 51651
Project: 51651
Buggy source:
@Override public void managerMode(InventoryClickEvent event){
  boolean top=event.getView().convertSlot(event.getRawSlot()) == event.getRawSlot();
  Player p=(Player)event.getWhoClicked();
  DecimalFormat f=new DecimalFormat("String_Node_Str");
  int clickedSlot=event.getSlot();
  if (clickedSlot < 0) {
    event.setCursor(null);
    switchInventory(getBasicManageModeByWool());
    return;
  }
  if (top) {
    setInventoryClicked(true);
    if (isManagementSlot(clickedSlot,3)) {
      if (isWool(event.getCurrentItem(),config.getItemManagement(6))) {
        if (isSellModeByWool())         this.setTraderStatus(TraderStatus.MANAGE_SELL);
        if (isBuyModeByWool())         this.setTraderStatus(TraderStatus.MANAGE_BUY);
        getInventory().setItem(getInventory().getSize() - 2,config.getItemManagement(2));
        getInventory().setItem(getInventory().getSize() - 3,(getBasicManageModeByWool().equals(TraderStatus.MANAGE_SELL) ? config.getItemManagement(5) : config.getItemManagement(3)));
        p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
      }
 else       if (isWool(event.getCurrentItem(),config.getItemManagement(2))) {
        if (!permissions.has(p,"String_Node_Str")) {
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
 else {
          this.setTraderStatus(TraderStatus.MANAGE_PRICE);
          getInventory().setItem(getInventory().getSize() - 2,config.getItemManagement(6));
          getInventory().setItem(getInventory().getSize() - 3,new ItemStack(Material.AIR));
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
      }
 else       if (isWool(event.getCurrentItem(),config.getItemManagement(3))) {
        if (!permissions.has(p,"String_Node_Str")) {
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
 else {
          setTraderStatus(TraderStatus.MANAGE_LIMIT_GLOBAL);
          getInventory().setItem(getInventory().getSize() - 2,new ItemStack(Material.WOOL,1,(short)0,(byte)0));
          getInventory().setItem(getInventory().getSize() - 3,new ItemStack(Material.AIR));
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
      }
 else       if (isWool(event.getCurrentItem(),config.getItemManagement(1))) {
        if (!permissions.has(p,"String_Node_Str")) {
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
 else {
          switchInventory(TraderStatus.MANAGE_BUY);
          getInventory().setItem(getInventory().getSize() - 1,config.getItemManagement(0));
          getInventory().setItem(getInventory().getSize() - 3,config.getItemManagement(3));
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
      }
 else       if (isWool(event.getCurrentItem(),config.getItemManagement(0))) {
        if (!permissions.has(p,"String_Node_Str")) {
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
 else {
          switchInventory(TraderStatus.MANAGE_SELL);
          getInventory().setItem(getInventory().getSize() - 1,config.getItemManagement(1));
          getInventory().setItem(getInventory().getSize() - 3,config.getItemManagement(4));
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
      }
 else       if (isWool(event.getCurrentItem(),config.getItemManagement(7))) {
        this.saveManagedAmouts();
        this.switchInventory(TraderStatus.MANAGE_SELL);
        getInventory().setItem(getInventory().getSize() - 1,config.getItemManagement(1));
        p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
      }
      event.setCancelled(true);
      return;
    }
 else {
      if (event.isShiftClick()) {
        event.setCancelled(true);
        if (isSellModeByWool()) {
          if (selectItem(clickedSlot,TraderStatus.MANAGE_SELL,p).hasSelectedItem()) {
            if (event.isLeftClick()) {
              int leftAmount=getSelectedItem().getLimitSystem().getGlobalLimit() - getSelectedItem().getLimitSystem().getGlobalAmount();
              if (inventoryHasPlaceAmount(p,leftAmount)) {
                if (isBuyModeByWool())                 getTraderStock().removeItem(false,clickedSlot);
                if (isSellModeByWool())                 getTraderStock().removeItem(true,clickedSlot);
                this.addAmountToInventory(p,leftAmount);
                getInventory().setItem(clickedSlot,new ItemStack(0));
                selectItem(null);
                p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
                p.sendMessage(locale.getLocaleString("String_Node_Str").replace("String_Node_Str","String_Node_Str" + leftAmount));
              }
            }
 else {
              if (permissions.has(p,"String_Node_Str")) {
                switchInventory(getSelectedItem());
                setTraderStatus(TraderStatus.MANAGE_SELL_AMOUNT);
              }
 else               p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
            }
          }
        }
 else         if (isBuyModeByWool()) {
          if (selectItem(clickedSlot,TraderStatus.MANAGE_BUY,p).hasSelectedItem()) {
            int stockedAmount=getSelectedItem().getLimitSystem().getGlobalAmount();
            if (inventoryHasPlaceAmount(p,stockedAmount)) {
              if (event.isLeftClick()) {
                if (isBuyModeByWool())                 getTraderStock().removeItem(false,clickedSlot);
                if (isSellModeByWool())                 getTraderStock().removeItem(true,clickedSlot);
                getInventory().setItem(clickedSlot,new ItemStack(0));
                p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
                p.sendMessage(locale.getLocaleString("String_Node_Str").replace("String_Node_Str","String_Node_Str" + stockedAmount));
              }
 else {
                p.sendMessage(locale.getLocaleString("String_Node_Str").replace("String_Node_Str","String_Node_Str" + stockedAmount));
                getSelectedItem().getLimitSystem().setGlobalAmount(0);
              }
              this.addAmountToInventory(p,stockedAmount);
              selectItem(null);
            }
          }
        }
        return;
      }
      if (equalsTraderStatus(getBasicManageModeByWool())) {
        if (event.isRightClick()) {
          if (selectItem(event.getSlot(),getTraderStatus(),p).hasSelectedItem()) {
            if (!permissions.has(p,"String_Node_Str")) {
              p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
              selectItem(null);
              event.setCancelled(true);
              return;
            }
            if (getSelectedItem().hasStackPrice()) {
              getSelectedItem().setStackPrice(false);
              p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str"));
            }
 else {
              getSelectedItem().setStackPrice(true);
              p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str"));
            }
          }
          selectItem(null);
          event.setCancelled(true);
          return;
        }
        if (hasSelectedItem()) {
          StockItem stockItem=getSelectedItem();
          if (selectItem(clickedSlot,getTraderStatus(),p).hasSelectedItem()) {
            getSelectedItem().setSlot(-2);
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str").replace("String_Node_Str",getSelectedMarketItem().getItemOwner()));
          }
 else           if (selectItem(clickedSlot,getTraderStatus()).hasSelectedItem()) {
            event.setCancelled(true);
            selectItem(stockItem);
            p.sendMessage(locale.getLocaleString("String_Node_Str"));
            return;
          }
          stockItem.setSlot(clickedSlot);
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str").replace("String_Node_Str",((MarketItem)stockItem).getItemOwner()));
        }
 else {
          if (selectItem(clickedSlot,getTraderStatus(),p).hasSelectedItem()) {
            getSelectedItem().setSlot(-2);
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str").replace("String_Node_Str",getSelectedMarketItem().getItemOwner()));
          }
 else           if (selectItem(clickedSlot,getTraderStatus()).hasSelectedItem()) {
            event.setCancelled(true);
            selectItem(null);
            p.sendMessage(locale.getLocaleString("String_Node_Str"));
            return;
          }
        }
        return;
      }
 else       if (equalsTraderStatus(TraderStatus.MANAGE_PRICE)) {
        if (event.getCursor().getType().equals(Material.AIR)) {
          if (selectItem(event.getSlot(),getBasicManageModeByWool(),p).hasSelectedItem())           p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str").replace("String_Node_Str",f.format(getSelectedItem().getRawPrice())));
        }
 else {
          if (selectItem(event.getSlot(),getBasicManageModeByWool(),p).hasSelectedItem()) {
            if (event.isRightClick())             getSelectedItem().lowerPrice(calculatePrice(event.getCursor()));
 else             getSelectedItem().increasePrice(calculatePrice(event.getCursor()));
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str").replace("String_Node_Str",f.format(getSelectedItem().getRawPrice())));
          }
        }
        selectItem(null);
        event.setCancelled(true);
      }
 else       if (equalsTraderStatus(TraderStatus.MANAGE_LIMIT_GLOBAL)) {
        if (event.getCursor().getType().equals(Material.AIR)) {
          if (selectItem(clickedSlot,getBasicManageModeByWool(),p).hasSelectedItem()) {
            p.sendMessage(locale.getLocaleString("String_Node_Str").replace("String_Node_Str","String_Node_Str" + getSelectedItem().getLimitSystem().getGlobalLimit()).replace("String_Node_Str","String_Node_Str" + getSelectedItem().getLimitSystem().getGlobalAmount()));
          }
        }
 else {
          if (selectItem(clickedSlot,getBasicManageModeByWool(),p).hasSelectedItem()) {
            if (event.isRightClick())             getSelectedItem().getLimitSystem().changeGlobalLimit(-calculateLimit(event.getCursor()));
 else             getSelectedItem().getLimitSystem().changeGlobalLimit(calculateLimit(event.getCursor()));
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str" + getSelectedItem().getLimitSystem().getGlobalLimit()));
          }
        }
        selectItem(null);
        event.setCancelled(true);
      }
 else       if (equalsTraderStatus(TraderStatus.MANAGE_LIMIT_PLAYER)) {
      }
 else       if (equalsTraderStatus(TraderStatus.MANAGE_SELL_AMOUNT)) {
        event.setCancelled(true);
        if (event.isLeftClick()) {
          if (event.getCurrentItem().getType().equals(Material.AIR)) {
            ItemStack clonedStack=getSelectedItem().getItemStack().clone();
            getInventory().setItem(clickedSlot,clonedStack);
            event.setCancelled(false);
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
          }
 else {
            int addAmount=event.getCursor().getAmount();
            if (event.getCursor().getTypeId() == 0)             addAmount=1;
            int oldAmount=event.getCurrentItem().getAmount();
            if (event.getCurrentItem().getMaxStackSize() < oldAmount + addAmount)             event.getCurrentItem().setAmount(event.getCurrentItem().getMaxStackSize());
 else             event.getCurrentItem().setAmount(oldAmount + addAmount);
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
          }
        }
 else {
          if (event.getCurrentItem().getTypeId() == 0) {
            return;
          }
          int removeAmount=event.getCursor().getAmount();
          if (event.getCursor().getTypeId() == 0)           removeAmount=1;
          int oldAmount=event.getCurrentItem().getAmount();
          if (oldAmount - removeAmount <= 0) {
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
            event.setCurrentItem(new ItemStack(Material.AIR,0));
          }
 else {
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
            event.getCurrentItem().setAmount(oldAmount - removeAmount);
          }
        }
      }
    }
  }
 else {
    if (equalsTraderStatus(TraderStatus.MANAGE_PRICE) || equalsTraderStatus(TraderStatus.MANAGE_LIMIT_GLOBAL) || equalsTraderStatus(TraderStatus.MANAGE_SELL_AMOUNT)) {
      if (event.isShiftClick())       event.setCancelled(true);
      return;
    }
    event.setCancelled(true);
    if (hasSelectedItem()) {
      if (event.getCursor().getTypeId() != 0) {
        event.setCursor(null);
        selectItem(null);
        switchInventory(getBasicManageModeByWool());
      }
    }
    if (event.isLeftClick() && event.getCurrentItem().getTypeId() != 0) {
      int backUpAmount=event.getCurrentItem().getAmount();
      ItemStack itemToAdd=event.getCurrentItem();
      itemToAdd.setAmount(1);
      this.selectMarketItem(itemToAdd,getBasicManageModeByWool(),p.getName(),false,false);
      if (hasSelectedItem()) {
        p.sendMessage(locale.getLocaleString("String_Node_Str"));
        itemToAdd.setAmount(backUpAmount);
        selectItem(null);
        setInventoryClicked(false);
        return;
      }
      int firstEmpty=getInventory().firstEmpty();
      if (firstEmpty >= 0 && firstEmpty < getInventory().getSize() - 3) {
        getInventory().setItem(firstEmpty,itemToAdd.clone());
        MarketItem marketItem=toMarketItem(itemToAdd.clone());
        marketItem.setAsPatternItem(false);
        marketItem.setPetternListening(false);
        marketItem.setItemOwner(p.getName());
        marketItem.setSlot(firstEmpty);
        LimitSystem limitSystem=marketItem.getLimitSystem();
        limitSystem.setGlobalLimit(0);
        limitSystem.setGlobalTimeout(-2000);
        if (isSellModeByWool())         getTraderStock().addItem(true,marketItem);
        if (isBuyModeByWool())         getTraderStock().addItem(false,marketItem);
        itemToAdd.setAmount(backUpAmount);
        p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
      }
    }
 else     if (event.getCurrentItem().getTypeId() != 0) {
      if (!event.isShiftClick()) {
        selectItem(null);
        setInventoryClicked(false);
        return;
      }
      if (equalsTraderStatus(TraderStatus.MANAGE_BUY))       return;
      ItemStack itemToAdd=event.getCurrentItem();
      this.selectMarketItem(itemToAdd,getBasicManageModeByWool(),p.getName(),false,false);
      if (hasSelectedItem()) {
        event.setCancelled(false);
        LimitSystem limitSystem=getSelectedItem().getLimitSystem();
        limitSystem.setGlobalTimeout(-2000);
        int getItemsLeft=limitSystem.getGlobalLimit() - limitSystem.getGlobalAmount();
        if (getItemsLeft < 0)         getItemsLeft=0;
        limitSystem.setGlobalLimit(getItemsLeft + itemToAdd.getAmount());
        p.sendMessage(locale.getLocaleString("String_Node_Str").replace("String_Node_Str",itemToAdd.getAmount() + "String_Node_Str").replace((itemToAdd.getAmount() != 1 ? "String_Node_Str" : "String_Node_Str"),"String_Node_Str"));
        itemToAdd.setAmount(0);
        event.setCurrentItem(itemToAdd);
        limitSystem.setGlobalAmount(0);
        selectItem(null);
      }
 else {
        p.sendMessage(locale.getLocaleString("String_Node_Str"));
      }
    }
  }
  setInventoryClicked(false);
}

Fixed version (ground truth):
@Override public void managerMode(InventoryClickEvent event){
  boolean top=event.getView().convertSlot(event.getRawSlot()) == event.getRawSlot();
  Player p=(Player)event.getWhoClicked();
  DecimalFormat f=new DecimalFormat("String_Node_Str");
  int clickedSlot=event.getSlot();
  if (clickedSlot < 0) {
    event.setCursor(null);
    switchInventory(getBasicManageModeByWool());
    return;
  }
  if (top) {
    setInventoryClicked(true);
    if (isManagementSlot(clickedSlot,3)) {
      if (isWool(event.getCurrentItem(),config.getItemManagement(6))) {
        if (isSellModeByWool())         this.setTraderStatus(TraderStatus.MANAGE_SELL);
        if (isBuyModeByWool())         this.setTraderStatus(TraderStatus.MANAGE_BUY);
        getInventory().setItem(getInventory().getSize() - 2,config.getItemManagement(2));
        getInventory().setItem(getInventory().getSize() - 3,(getBasicManageModeByWool().equals(TraderStatus.MANAGE_SELL) ? config.getItemManagement(5) : config.getItemManagement(3)));
        p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
      }
 else       if (isWool(event.getCurrentItem(),config.getItemManagement(2))) {
        if (!permissions.has(p,"String_Node_Str")) {
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
 else {
          this.setTraderStatus(TraderStatus.MANAGE_PRICE);
          getInventory().setItem(getInventory().getSize() - 2,config.getItemManagement(6));
          getInventory().setItem(getInventory().getSize() - 3,new ItemStack(Material.AIR));
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
      }
 else       if (isWool(event.getCurrentItem(),config.getItemManagement(3))) {
        if (!permissions.has(p,"String_Node_Str")) {
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
 else {
          setTraderStatus(TraderStatus.MANAGE_LIMIT_GLOBAL);
          getInventory().setItem(getInventory().getSize() - 2,new ItemStack(Material.WOOL,1,(short)0,(byte)0));
          getInventory().setItem(getInventory().getSize() - 3,new ItemStack(Material.AIR));
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
      }
 else       if (isWool(event.getCurrentItem(),config.getItemManagement(1))) {
        if (!permissions.has(p,"String_Node_Str")) {
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
 else {
          switchInventory(TraderStatus.MANAGE_BUY);
          getInventory().setItem(getInventory().getSize() - 1,config.getItemManagement(0));
          getInventory().setItem(getInventory().getSize() - 3,config.getItemManagement(3));
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
      }
 else       if (isWool(event.getCurrentItem(),config.getItemManagement(0))) {
        if (!permissions.has(p,"String_Node_Str")) {
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
 else {
          switchInventory(TraderStatus.MANAGE_SELL);
          getInventory().setItem(getInventory().getSize() - 1,config.getItemManagement(1));
          getInventory().setItem(getInventory().getSize() - 3,config.getItemManagement(4));
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
        }
      }
 else       if (isWool(event.getCurrentItem(),config.getItemManagement(7))) {
        this.saveManagedAmouts();
        this.switchInventory(TraderStatus.MANAGE_SELL);
        getInventory().setItem(getInventory().getSize() - 1,config.getItemManagement(1));
        p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
      }
      event.setCancelled(true);
      return;
    }
 else {
      if (event.isShiftClick()) {
        event.setCancelled(true);
        if (isSellModeByWool()) {
          if (selectItem(clickedSlot,TraderStatus.MANAGE_SELL,p).hasSelectedItem()) {
            if (event.isLeftClick()) {
              int leftAmount=getSelectedItem().getLimitSystem().getGlobalLimit() - getSelectedItem().getLimitSystem().getGlobalAmount();
              if (inventoryHasPlaceAmount(p,leftAmount)) {
                if (isBuyModeByWool())                 getTraderStock().removeItem(false,clickedSlot);
                if (isSellModeByWool())                 getTraderStock().removeItem(true,clickedSlot);
                this.addAmountToInventory(p,leftAmount);
                getInventory().setItem(clickedSlot,new ItemStack(0));
                selectItem(null);
                p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
                p.sendMessage(locale.getLocaleString("String_Node_Str").replace("String_Node_Str","String_Node_Str" + leftAmount));
              }
            }
 else {
              if (permissions.has(p,"String_Node_Str")) {
                switchInventory(getSelectedItem());
                setTraderStatus(TraderStatus.MANAGE_SELL_AMOUNT);
              }
 else               p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
            }
          }
        }
 else         if (isBuyModeByWool()) {
          if (selectItem(clickedSlot,TraderStatus.MANAGE_BUY,p).hasSelectedItem()) {
            int stockedAmount=getSelectedItem().getLimitSystem().getGlobalAmount();
            if (inventoryHasPlaceAmount(p,stockedAmount)) {
              if (event.isLeftClick()) {
                if (isBuyModeByWool())                 getTraderStock().removeItem(false,clickedSlot);
                if (isSellModeByWool())                 getTraderStock().removeItem(true,clickedSlot);
                getInventory().setItem(clickedSlot,new ItemStack(0));
                p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
                p.sendMessage(locale.getLocaleString("String_Node_Str").replace("String_Node_Str","String_Node_Str" + stockedAmount));
              }
 else {
                p.sendMessage(locale.getLocaleString("String_Node_Str").replace("String_Node_Str","String_Node_Str" + stockedAmount));
                getSelectedItem().getLimitSystem().setGlobalAmount(0);
              }
              this.addAmountToInventory(p,stockedAmount);
              selectItem(null);
            }
          }
        }
        return;
      }
      if (equalsTraderStatus(getBasicManageModeByWool())) {
        if (event.isRightClick()) {
          if (selectItem(event.getSlot(),getTraderStatus(),p).hasSelectedItem()) {
            if (!permissions.has(p,"String_Node_Str")) {
              p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str"));
              selectItem(null);
              event.setCancelled(true);
              return;
            }
            if (getSelectedItem().hasStackPrice()) {
              getSelectedItem().setStackPrice(false);
              p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str"));
            }
 else {
              getSelectedItem().setStackPrice(true);
              p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str"));
            }
          }
          selectItem(null);
          event.setCancelled(true);
          return;
        }
        if (hasSelectedItem()) {
          StockItem stockItem=getSelectedItem();
          if (selectItem(clickedSlot,getTraderStatus(),p).hasSelectedItem()) {
            getSelectedItem().setSlot(-2);
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str").replace("String_Node_Str",getSelectedMarketItem().getItemOwner()));
          }
 else           if (selectItem(clickedSlot,getTraderStatus()).hasSelectedItem()) {
            event.setCancelled(true);
            selectItem(stockItem);
            p.sendMessage(locale.getLocaleString("String_Node_Str"));
            return;
          }
          stockItem.setSlot(clickedSlot);
          p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str").replace("String_Node_Str",((MarketItem)stockItem).getItemOwner()));
        }
 else {
          if (selectItem(clickedSlot,getTraderStatus(),p).hasSelectedItem()) {
            getSelectedItem().setSlot(-2);
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str").replace("String_Node_Str",getSelectedMarketItem().getItemOwner()));
          }
 else           if (selectItem(clickedSlot,getTraderStatus()).hasSelectedItem()) {
            event.setCancelled(true);
            selectItem(null);
            p.sendMessage(locale.getLocaleString("String_Node_Str"));
            return;
          }
        }
        return;
      }
 else       if (equalsTraderStatus(TraderStatus.MANAGE_PRICE)) {
        if (event.getCursor().getType().equals(Material.AIR)) {
          if (selectItem(event.getSlot(),getBasicManageModeByWool(),p).hasSelectedItem())           p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str").replace("String_Node_Str",f.format(getSelectedItem().getRawPrice())));
        }
 else {
          if (selectItem(event.getSlot(),getBasicManageModeByWool(),p).hasSelectedItem()) {
            if (event.isRightClick())             getSelectedItem().lowerPrice(calculatePrice(event.getCursor()));
 else             getSelectedItem().increasePrice(calculatePrice(event.getCursor()));
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str").replace("String_Node_Str",f.format(getSelectedItem().getRawPrice())));
          }
        }
        selectItem(null);
        event.setCancelled(true);
      }
 else       if (equalsTraderStatus(TraderStatus.MANAGE_LIMIT_GLOBAL)) {
        if (event.getCursor().getType().equals(Material.AIR)) {
          if (selectItem(clickedSlot,getBasicManageModeByWool(),p).hasSelectedItem()) {
            p.sendMessage(locale.getLocaleString("String_Node_Str").replace("String_Node_Str","String_Node_Str" + getSelectedItem().getLimitSystem().getGlobalLimit()).replace("String_Node_Str","String_Node_Str" + getSelectedItem().getLimitSystem().getGlobalAmount()));
          }
        }
 else {
          if (selectItem(clickedSlot,getBasicManageModeByWool(),p).hasSelectedItem()) {
            if (event.isRightClick())             getSelectedItem().getLimitSystem().changeGlobalLimit(-calculateLimit(event.getCursor()));
 else             getSelectedItem().getLimitSystem().changeGlobalLimit(calculateLimit(event.getCursor()));
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str" + getSelectedItem().getLimitSystem().getGlobalLimit()));
          }
        }
        selectItem(null);
        event.setCancelled(true);
      }
 else       if (equalsTraderStatus(TraderStatus.MANAGE_LIMIT_PLAYER)) {
      }
 else       if (equalsTraderStatus(TraderStatus.MANAGE_SELL_AMOUNT)) {
        event.setCancelled(true);
        if (event.isLeftClick()) {
          if (event.getCurrentItem().getType().equals(Material.AIR)) {
            ItemStack clonedStack=getSelectedItem().getItemStack().clone();
            getInventory().setItem(clickedSlot,clonedStack);
            event.setCancelled(false);
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
          }
 else {
            int addAmount=event.getCursor().getAmount();
            if (event.getCursor().getTypeId() == 0)             addAmount=1;
            int oldAmount=event.getCurrentItem().getAmount();
            if (event.getCurrentItem().getMaxStackSize() < oldAmount + addAmount)             event.getCurrentItem().setAmount(event.getCurrentItem().getMaxStackSize());
 else             event.getCurrentItem().setAmount(oldAmount + addAmount);
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
          }
        }
 else {
          if (event.getCurrentItem().getTypeId() == 0) {
            return;
          }
          int removeAmount=event.getCursor().getAmount();
          if (event.getCursor().getTypeId() == 0)           removeAmount=1;
          int oldAmount=event.getCurrentItem().getAmount();
          if (oldAmount - removeAmount <= 0) {
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
            event.setCurrentItem(new ItemStack(Material.AIR,0));
          }
 else {
            p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
            event.getCurrentItem().setAmount(oldAmount - removeAmount);
          }
        }
      }
    }
  }
 else {
    if (equalsTraderStatus(TraderStatus.MANAGE_PRICE) || equalsTraderStatus(TraderStatus.MANAGE_LIMIT_GLOBAL) || equalsTraderStatus(TraderStatus.MANAGE_SELL_AMOUNT)) {
      if (event.isShiftClick())       event.setCancelled(true);
      return;
    }
    event.setCancelled(true);
    if (hasSelectedItem()) {
      if (event.getCursor().getTypeId() != 0) {
        event.setCursor(null);
        selectItem(null);
        switchInventory(getBasicManageModeByWool());
      }
    }
    if (event.isLeftClick() && event.getCurrentItem().getTypeId() != 0) {
      int backUpAmount=event.getCurrentItem().getAmount();
      ItemStack itemToAdd=event.getCurrentItem();
      itemToAdd.setAmount(1);
      this.selectItem(itemToAdd,getBasicManageModeByWool(),false,false);
      if (hasSelectedItem()) {
        p.sendMessage(locale.getLocaleString("String_Node_Str"));
        itemToAdd.setAmount(backUpAmount);
        selectItem(null);
        setInventoryClicked(false);
        return;
      }
      int firstEmpty=getInventory().firstEmpty();
      if (firstEmpty >= 0 && firstEmpty < getInventory().getSize() - 3) {
        getInventory().setItem(firstEmpty,itemToAdd.clone());
        MarketItem marketItem=toMarketItem(itemToAdd.clone());
        marketItem.setAsPatternItem(false);
        marketItem.setPetternListening(false);
        marketItem.setItemOwner(p.getName());
        marketItem.setSlot(firstEmpty);
        LimitSystem limitSystem=marketItem.getLimitSystem();
        limitSystem.setGlobalLimit(0);
        limitSystem.setGlobalTimeout(-2000);
        if (isSellModeByWool())         getTraderStock().addItem(true,marketItem);
        if (isBuyModeByWool())         getTraderStock().addItem(false,marketItem);
        itemToAdd.setAmount(backUpAmount);
        p.sendMessage(locale.getLocaleString("String_Node_Str","String_Node_Str"));
      }
    }
 else     if (event.getCurrentItem().getTypeId() != 0) {
      if (!event.isShiftClick()) {
        selectItem(null);
        setInventoryClicked(false);
        return;
      }
      if (equalsTraderStatus(TraderStatus.MANAGE_BUY))       return;
      ItemStack itemToAdd=event.getCurrentItem();
      this.selectItem(itemToAdd,getBasicManageModeByWool(),false,false);
      if (hasSelectedItem()) {
        event.setCancelled(false);
        LimitSystem limitSystem=getSelectedItem().getLimitSystem();
        limitSystem.setGlobalTimeout(-2000);
        int getItemsLeft=limitSystem.getGlobalLimit() - limitSystem.getGlobalAmount();
        if (getItemsLeft < 0)         getItemsLeft=0;
        limitSystem.setGlobalLimit(getItemsLeft + itemToAdd.getAmount());
        p.sendMessage(locale.getLocaleString("String_Node_Str").replace("String_Node_Str",itemToAdd.getAmount() + "String_Node_Str").replace((itemToAdd.getAmount() != 1 ? "String_Node_Str" : "String_Node_Str"),"String_Node_Str"));
        itemToAdd.setAmount(0);
        event.setCurrentItem(itemToAdd);
        limitSystem.setGlobalAmount(0);
        selectItem(null);
      }
 else {
        p.sendMessage(locale.getLocaleString("String_Node_Str"));
      }
    }
  }
  setInventoryClicked(false);
}