/** * Withdraws or deposits the amounts required to ensure the user has the exact amount of the * specified id. * * @param id the item id you wish to check. * @param amount the amount of said id you are aiming for. * @throws InterruptedException */ public void ensureUserHasAmount(int id, int amount) throws InterruptedException { Inventory inv = ctx.client.getInventory(); Bank bank = ctx.client.getBank(); if (inv != null && bank != null) { if (amount >= 1 && inv.getAmount(id) != amount) { if (inv.getAmount(id) > amount) { if (bank.deposit(id, (int) (inv.getAmount(id) - amount))) { Timer timer = new Timer(2000); while (timer.isRunning() && (inv.getAmount(id) > amount)) ctx.sleep(50); } } else { if (!bank.contains(id)) { bank.close(); ctx.stop(); return; } if (inv.getEmptySlots() < amount - inv.getAmount(id) && amount <= 28) { Item itemInInv = inv.getItemForId(id); if (itemInInv == null || itemInInv.getAmount() <= 1) return; } if (bank.withdraw(id, (int) (amount - inv.getAmount(id)))) { Timer timer = new Timer(2000); while (timer.isRunning() && (inv.getAmount(id) < amount)) ctx.sleep(50); } } } else bank.depositAll(id); } }
/** * Returns whether the player has the specified amount of items that match the id specified. * * @param id the item id you wish to check. * @param amount the amount of said id you are checking for. * @return whether the player has the specified amount of items that match the id specified. * @throws InterruptedException */ public boolean hasAmount(int id, int amount) throws InterruptedException { Inventory inv = ctx.client.getInventory(); Bank bank = ctx.client.getBank(); if (inv != null && bank != null) { if (amount == 0) return inv.getAmount(id) >= 1; if (amount >= 1) return inv.getAmount(id) == amount; } return false; }