public L2ItemInstance addItem(String process, L2ItemInstance item, L2PcInstance actor, L2Object reference) { L2ItemInstance olditem = getItemByItemId(item.getItemId()); // If stackable item is found in inventory just add to current quantity if (olditem != null && olditem.isStackable()) { olditem.changeCount(process, item.getCount(), actor, reference); olditem.setLastChange(L2ItemInstance.MODIFIED); // And destroys the item ItemTable.getInstance().destroyItem(process, item, actor, reference); item.updateDatabase(); item = olditem; } // If item hasn't be found in inventory, create new one else { item.setOwnerId(process, getOwnerId(), actor, reference); item.setLocation(getBaseLocation()); item.setLastChange((L2ItemInstance.ADDED)); // Add item in inventory addItem(item); } // Updates database item.updateDatabase(); refreshWeight(); return item; }