public void collectSlot2() { /* * Collects money slot */ if (currentOffer == null) { p.getPackets().sendMessage("[collectSlot2]: Nice try cheater!, If this is bug please report it."); return; } if (currentOffer.getSlot2() != null) { int playerInventoryGoldAmount = p.getInventory().getItemAmount(995); int grandExchangeSlot2GoldAmountToWithdraw = currentOffer.getSlot2().getItemAmount(); if (playerInventoryGoldAmount >= Inventory.MAX_ITEM_AMOUNT) { p.getPackets().sendMessage("You cannot collect anymore money, you have maximum money in inventory."); return; } //if player's inventory gold + slot2 gold is more then you can hold for that inventory item. /* * have to cast both amounts with (long) * because the way they are both (int)'s, they might create a negitive number * and that negitive number is less then MAX_ITEM_AMOUNT so it wont work properly. */ if (((long)playerInventoryGoldAmount + (long)grandExchangeSlot2GoldAmountToWithdraw) > Inventory.MAX_ITEM_AMOUNT) { grandExchangeSlot2GoldAmountToWithdraw = (Inventory.MAX_ITEM_AMOUNT - playerInventoryGoldAmount); } /* * Change Slot2's amount based on how much left over * if any when added to inventory after max item amount check. */ if (p.getInventory().addItem(995, grandExchangeSlot2GoldAmountToWithdraw)) { currentOffer.getSlot2().setItemAmount(currentOffer.getSlot2().getItemAmount() - grandExchangeSlot2GoldAmountToWithdraw); } currentOffer.setAmountCollectedGold(currentOffer.getAmountCollectedGold() + grandExchangeSlot2GoldAmountToWithdraw); /* * Clear Slot2's Gold Item, if gold item amount <=0 */ if (currentOffer.getSlot2().getItemAmount() <= 0) { currentOffer.setSlot2(null); } updateSlotStates(); } }