Created
May 4, 2018 19:33
-
-
Save drusepth/f49678c43030518c1d11306ff0d61536 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package scripts.caches; | |
| import org.powerbot.script.rt4.ClientContext; | |
| import org.powerbot.script.rt4.Item; | |
| import java.sql.Timestamp; | |
| import java.util.Date; | |
| public class BankCache { | |
| java.util.Hashtable<Integer, Integer> item_quantity; | |
| Timestamp last_updated; | |
| public BankCache() { | |
| item_quantity = new java.util.Hashtable<Integer, Integer>(); | |
| last_updated = null; | |
| } | |
| public void update(ClientContext ctx) { | |
| if (ctx.bank.opened()) { | |
| for (Item item : ctx.bank.select()) { | |
| item_quantity.put(item.id(), item.stackSize()); | |
| } | |
| last_updated = new Timestamp(new Date().getTime()); | |
| } | |
| } | |
| public double seconds_since_update() { | |
| if (last_updated == null) { | |
| return Double.POSITIVE_INFINITY; | |
| } else { | |
| return new Timestamp(new Date().getTime()).getTime() - last_updated.getTime(); | |
| } | |
| } | |
| public int quantity(int item_id) { | |
| if (item_quantity.containsKey(item_id)) { | |
| return item_quantity.get(item_id); | |
| } else { | |
| return 0; | |
| } | |
| } | |
| public void bust() { | |
| item_quantity.clear(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment