Program: 11766
Project: 11766
Buggy source:
@Override public void handleReceived(ClientConnection connection){
  if (mode == null) {
    return;
  }
  TridentPlayer player=((PlayerConnection)connection).player();
  Inventory window=Registered.inventories().fromId(this.windowId);
  Inventory originalWindow=window;
  int originalSlot=clickedSlot;
  if (clickedSlot >= window.length()) {
    clickedSlot+=(9 - window.length());
    window=player.window();
  }
  PlayerClickItemEvent clickEvent=EventProcessor.fire(new PlayerClickItemEvent(window,this.clickedSlot,(int)this.actionNumber));
  if (clickEvent.isIgnored()) {
    return;
  }
switch (mode) {
case LEFT_CLICK:
case RIGHT_CLICK:
    if (player.pickedItem() == null) {
      if (window.itemAt(clickedSlot) != null && window.itemAt(clickedSlot).type() != Substance.AIR) {
        if (window.itemAt(clickedSlot).isSimilar(clickedItem.item())) {
          if (mode == ClickAction.LEFT_CLICK) {
            player.setPickedItem(clickedItem.item());
            window.setSlot(clickedSlot,null);
          }
 else {
            Item cursor=clickedItem.item().clone();
            cursor.setQuantity((short)Math.ceil((cursor.quantity() / 2)));
            player.setPickedItem(cursor);
            window.itemAt(clickedSlot).setQuantity((short)(window.itemAt(clickedSlot).quantity() - cursor.quantity()));
            window.setSlot(clickedSlot,window.itemAt(clickedSlot));
          }
        }
 else {
          TridentLogger.get().warn(player.name() + "String_Node_Str");
        }
      }
    }
 else {
      Item temp=window.itemAt(clickedSlot);
      if (mode == ClickAction.LEFT_CLICK) {
        window.setSlot(clickedSlot,player.pickedItem());
        if (temp != null && temp.type() != Substance.AIR) {
          player.setPickedItem(temp);
        }
 else {
          player.setPickedItem(null);
        }
      }
 else {
        if (temp == null || temp.type() == Substance.AIR) {
          Item single=player.pickedItem().clone();
          single.setQuantity((short)1);
          window.setSlot(clickedSlot,single);
          if (player.pickedItem().quantity() > 1) {
            player.pickedItem().setQuantity((short)(player.pickedItem().quantity() - 1));
          }
 else {
            player.setPickedItem(null);
          }
        }
 else {
          window.setSlot(clickedSlot,player.pickedItem());
          if (temp.type() != Substance.AIR) {
            player.setPickedItem(temp);
          }
 else {
            player.setPickedItem(null);
          }
        }
      }
    }
  break;
case SHIFT_LEFT_CLICK:
break;
case SHIFT_RIGHT_CLICK:
break;
case NUMBER_KEY:
break;
case MIDDLE_CLICK:
break;
case DROP_KEY_ONE:
break;
case DROP_KEY_STACK:
break;
case LEFT_CLICK_OUTSIDE:
break;
case RIGHT_CLICK_OUTSIDE:
break;
case START_LEFT_CLICK_DRAG:
case START_RIGHT_CLICK_DRAG:
if (player.drag() != null) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
player.setDrag(mode);
break;
case ADD_SLOT_LEFT_CLICK_DRAG:
case ADD_SLOT_RIGHT_CLICK_DRAG:
if (player.drag() == null) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
 else {
if ((mode == ClickAction.ADD_SLOT_LEFT_CLICK_DRAG && player.drag() == ClickAction.START_RIGHT_CLICK_DRAG) || (mode == ClickAction.ADD_SLOT_RIGHT_CLICK_DRAG && player.drag() == ClickAction.START_LEFT_CLICK_DRAG)) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
}
player.dragSlots().add((int)originalSlot);
break;
case END_LEFT_CLICK_DRAG:
if (player.drag() == null) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
 else if (player.drag() == ClickAction.START_RIGHT_CLICK_DRAG) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
int available=player.pickedItem().quantity();
int split=(int)Math.floor(available / player.dragSlots().size());
for (Integer i : player.dragSlots()) {
if (available == 0) {
break;
}
Inventory using=originalWindow;
if (i >= originalWindow.length()) {
using=player.window();
}
Item current=using.itemAt(i);
if (current == null || current.type() == Substance.AIR) {
current=player.pickedItem().clone();
current.setQuantity((short)split);
using.setSlot(i,current);
available-=split;
}
 else if (current.isSimilarIgnoreQuantity(player.pickedItem()) && current.quantity() < current.type().maxStackSize()) {
int canAdd=Math.min(split,current.type().maxStackSize() - current.quantity());
current.setQuantity((short)(current.quantity() + canAdd));
using.setSlot(i,current);
available-=canAdd;
}
}
if (available == 0) {
player.setPickedItem(null);
}
 else {
player.pickedItem().setQuantity((short)available);
}
player.dragSlots().clear();
player.setDrag(null);
break;
case END_RIGHT_CLICK_DRAG:
if (player.drag() == null) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
 else if (player.drag() == ClickAction.START_LEFT_CLICK_DRAG) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
available=player.pickedItem().quantity();
for (Integer i : player.dragSlots()) {
if (available == 0) {
break;
}
Inventory using=originalWindow;
if (i >= originalWindow.length()) {
using=player.window();
}
Item current=using.itemAt(i);
if (current == null || current.type() == Substance.AIR) {
current=player.pickedItem().clone();
current.setQuantity((short)1);
using.setSlot(i,current);
available--;
}
 else if (current.isSimilarIgnoreQuantity(player.pickedItem()) && current.quantity() < current.type().maxStackSize()) {
current.setQuantity((short)(current.quantity() + 1));
using.setSlot(i,current);
available--;
}
}
if (available == 0) {
player.setPickedItem(null);
}
 else {
player.pickedItem().setQuantity((short)available);
}
player.dragSlots().clear();
player.setDrag(null);
break;
case DOUBLE_CLICK:
Item picking=window.itemAt(clickedSlot);
if (player.pickedItem() != null) {
picking=player.pickedItem();
}
int count=picking.quantity();
int slot=0;
if (window.id() != windowId) {
window=originalWindow;
}
while (count <= picking.type().maxStackSize() && slot < window.length()) {
if (window.itemAt(slot) != null && window.itemAt(slot).isSimilarIgnoreQuantity(picking)) {
if (count + window.itemAt(slot).quantity() <= picking.type().maxStackSize()) {
count+=window.itemAt(slot).quantity();
window.setSlot(slot,null);
}
 else {
window.itemAt(slot).setQuantity((short)(window.itemAt(slot).quantity() - (picking.type().maxStackSize() - count)));
window.setSlot(slot,window.itemAt(slot));
count=picking.type().maxStackSize();
break;
}
}
slot++;
}
if (count < picking.type().maxStackSize() && windowId > 0) {
slot=0;
Inventory pW=player.window();
while (count <= picking.type().maxStackSize() && slot < pW.length()) {
if (pW.itemAt(slot) != null && pW.itemAt(slot).isSimilarIgnoreQuantity(picking)) {
if (count + pW.itemAt(slot).quantity() <= picking.type().maxStackSize()) {
count+=pW.itemAt(slot).quantity();
pW.setSlot(slot,null);
}
 else {
pW.itemAt(slot).setQuantity((short)(pW.itemAt(slot).quantity() - (picking.type().maxStackSize() - count)));
pW.setSlot(slot,pW.itemAt(slot));
count=picking.type().maxStackSize();
break;
}
}
slot++;
}
}
picking.setQuantity((short)count);
player.setPickedItem(picking);
break;
}
}

Fixed version (ground truth):
@Override public void handleReceived(ClientConnection connection){
  if (mode == null) {
    return;
  }
  TridentPlayer player=((PlayerConnection)connection).player();
  Inventory window=Registered.inventories().fromId(this.windowId);
  Inventory originalWindow=window;
  int originalSlot=clickedSlot;
  if (clickedSlot >= window.length()) {
    clickedSlot+=(9 - window.length());
    window=player.window();
  }
  PlayerClickItemEvent clickEvent=EventProcessor.fire(new PlayerClickItemEvent(window,this.clickedSlot,(int)this.actionNumber));
  if (clickEvent.isIgnored()) {
    return;
  }
switch (mode) {
case LEFT_CLICK:
case RIGHT_CLICK:
    if (player.pickedItem() == null) {
      if (window.itemAt(clickedSlot) != null && window.itemAt(clickedSlot).type() != Substance.AIR) {
        if (window.itemAt(clickedSlot).isSimilar(clickedItem.item())) {
          if (mode == ClickAction.LEFT_CLICK) {
            player.setPickedItem(clickedItem.item());
            window.setSlot(clickedSlot,null);
          }
 else {
            Item cursor=clickedItem.item().clone();
            cursor.setQuantity((short)Math.ceil((cursor.quantity() / 2)));
            player.setPickedItem(cursor);
            window.itemAt(clickedSlot).setQuantity((short)(window.itemAt(clickedSlot).quantity() - cursor.quantity()));
            window.setSlot(clickedSlot,window.itemAt(clickedSlot));
          }
        }
 else {
          TridentLogger.get().warn(player.name() + "String_Node_Str");
        }
      }
    }
 else {
      Item temp=window.itemAt(clickedSlot);
      if (mode == ClickAction.LEFT_CLICK) {
        window.setSlot(clickedSlot,player.pickedItem());
        if (temp != null && temp.type() != Substance.AIR) {
          player.setPickedItem(temp);
        }
 else {
          player.setPickedItem(null);
        }
      }
 else {
        if (temp == null || temp.type() == Substance.AIR) {
          Item single=player.pickedItem().clone();
          single.setQuantity((short)1);
          window.setSlot(clickedSlot,single);
          if (player.pickedItem().quantity() > 1) {
            player.pickedItem().setQuantity((short)(player.pickedItem().quantity() - 1));
          }
 else {
            player.setPickedItem(null);
          }
        }
 else {
          window.setSlot(clickedSlot,player.pickedItem());
          if (temp.type() != Substance.AIR) {
            player.setPickedItem(temp);
          }
 else {
            player.setPickedItem(null);
          }
        }
      }
    }
  break;
case SHIFT_LEFT_CLICK:
break;
case SHIFT_RIGHT_CLICK:
break;
case NUMBER_KEY:
break;
case MIDDLE_CLICK:
break;
case DROP_KEY_ONE:
break;
case DROP_KEY_STACK:
break;
case LEFT_CLICK_OUTSIDE:
break;
case RIGHT_CLICK_OUTSIDE:
break;
case START_LEFT_CLICK_DRAG:
case START_RIGHT_CLICK_DRAG:
if (player.drag() != null) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
player.setDrag(mode);
break;
case ADD_SLOT_LEFT_CLICK_DRAG:
case ADD_SLOT_RIGHT_CLICK_DRAG:
if (player.drag() == null) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
 else {
if ((mode == ClickAction.ADD_SLOT_LEFT_CLICK_DRAG && player.drag() == ClickAction.START_RIGHT_CLICK_DRAG) || (mode == ClickAction.ADD_SLOT_RIGHT_CLICK_DRAG && player.drag() == ClickAction.START_LEFT_CLICK_DRAG)) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
}
player.dragSlots().add((int)originalSlot);
break;
case END_LEFT_CLICK_DRAG:
if (player.drag() == null) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
 else if (player.drag() == ClickAction.START_RIGHT_CLICK_DRAG) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
int available=player.pickedItem().quantity();
int split=(int)Math.floor(available / player.dragSlots().size());
for (Integer i : player.dragSlots()) {
if (available == 0) {
break;
}
Inventory using=originalWindow;
if (i >= originalWindow.length()) {
using=player.window();
}
Item current=using.itemAt(i);
if (current == null || current.type() == Substance.AIR) {
current=player.pickedItem().clone();
current.setQuantity((short)split);
using.setSlot(i,current);
available-=split;
}
 else if (current.isSimilarIgnoreQuantity(player.pickedItem()) && current.quantity() < current.type().maxStackSize()) {
int canAdd=Math.min(split,current.type().maxStackSize() - current.quantity());
current.setQuantity((short)(current.quantity() + canAdd));
using.setSlot(i,current);
available-=canAdd;
}
}
if (available == 0) {
player.setPickedItem(null);
}
 else {
player.pickedItem().setQuantity((short)available);
}
player.dragSlots().clear();
player.setDrag(null);
break;
case END_RIGHT_CLICK_DRAG:
if (player.drag() == null) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
 else if (player.drag() == ClickAction.START_LEFT_CLICK_DRAG) {
TridentLogger.get().warn(player.name() + "String_Node_Str");
break;
}
System.out.println(player.pickedItem());
available=player.pickedItem().quantity();
for (Integer i : player.dragSlots()) {
if (available == 0) {
break;
}
Inventory using=originalWindow;
if (i >= originalWindow.length()) {
using=player.window();
}
Item current=using.itemAt(i);
if (current == null || current.type() == Substance.AIR) {
current=player.pickedItem().clone();
current.setQuantity((short)1);
using.setSlot(i,current);
available--;
}
 else if (current.isSimilarIgnoreQuantity(player.pickedItem()) && current.quantity() < current.type().maxStackSize()) {
current.setQuantity((short)(current.quantity() + 1));
using.setSlot(i,current);
available--;
}
}
if (available == 0) {
player.setPickedItem(null);
}
 else {
player.pickedItem().setQuantity((short)available);
}
player.dragSlots().clear();
player.setDrag(null);
break;
case DOUBLE_CLICK:
Item picking=window.itemAt(clickedSlot);
if (player.pickedItem() != null) {
picking=player.pickedItem();
}
int count=picking.quantity();
int slot=0;
if (window.id() != windowId) {
window=originalWindow;
}
while (count <= picking.type().maxStackSize() && slot < window.length()) {
if (window.itemAt(slot) != null && window.itemAt(slot).isSimilarIgnoreQuantity(picking)) {
if (count + window.itemAt(slot).quantity() <= picking.type().maxStackSize()) {
count+=window.itemAt(slot).quantity();
window.setSlot(slot,null);
}
 else {
window.itemAt(slot).setQuantity((short)(window.itemAt(slot).quantity() - (picking.type().maxStackSize() - count)));
window.setSlot(slot,window.itemAt(slot));
count=picking.type().maxStackSize();
break;
}
}
slot++;
}
if (count < picking.type().maxStackSize() && windowId > 0) {
slot=0;
Inventory pW=player.window();
while (count <= picking.type().maxStackSize() && slot < pW.length()) {
if (pW.itemAt(slot) != null && pW.itemAt(slot).isSimilarIgnoreQuantity(picking)) {
if (count + pW.itemAt(slot).quantity() <= picking.type().maxStackSize()) {
count+=pW.itemAt(slot).quantity();
pW.setSlot(slot,null);
}
 else {
pW.itemAt(slot).setQuantity((short)(pW.itemAt(slot).quantity() - (picking.type().maxStackSize() - count)));
pW.setSlot(slot,pW.itemAt(slot));
count=picking.type().maxStackSize();
break;
}
}
slot++;
}
}
picking.setQuantity((short)count);
player.setPickedItem(picking);
break;
}
}