Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FruityGrandExchange extends API {
- private final GrandExchange ge;
- public FruityGrandExchange(FruityZulrah script) {
- this.ge = script.getGrandExchange();
- exchangeContext(script.getBot());
- }
- public boolean sell(Exchange exchange) {
- SellItemEvent event = new SellItemEvent(exchange);
- return execute(event).hasFinished();
- }
- public boolean buy(Exchange exchange) {
- BuyItemEvent event = new BuyItemEvent(exchange);
- return execute(event).hasFinished();
- }
- public boolean open() {
- Entity booth = getBooth();
- if (booth != null && booth.interact("Exchange")) {
- Time.sleep(ge::isOpen);
- return true;
- }
- return false;
- }
- public boolean close() {
- if (ge.close()) {
- Time.sleep(() -> !ge.isOpen());
- return true;
- }
- return false;
- }
- public Entity getBooth() {
- return getObjects().closest(i -> i.getName().contains("Grand Exchange booth") && i.hasAction("Exchange"));
- }
- public List<GrandExchange.Box> getBoxes() {
- return Arrays.asList(GrandExchange.Box.values());
- }
- public GrandExchange.Box getBox(Predicate<GrandExchange.Box> predicate) {
- return getBoxes().stream().filter(predicate).findFirst().orElse(null);
- }
- public List<GrandExchange.Box> getBoxes(Predicate<GrandExchange.Box> predicate) {
- return getBoxes().stream().filter(predicate).collect(Collectors.toList());
- }
- public List<GrandExchange.Box> getCompletedBoxes() {
- return getBoxes(box -> {
- GrandExchange.Status status = ge.getStatus(box);
- return status == GrandExchange.Status.FINISHED_BUY || status == GrandExchange.Status.FINISHED_SALE;
- });
- }
- public List<GrandExchange.Box> getEmptyBoxes() {
- return getBoxes(box -> ge.getStatus(box) == GrandExchange.Status.EMPTY);
- }
- public List<GrandExchange.Box> getOffers() {
- return getBoxes(box -> ge.getStatus(box) != GrandExchange.Status.EMPTY);
- }
- public List<Integer> getItems() {
- List<Integer> items = new ArrayList<>();
- getOffers().forEach(box -> items.add(ge.getItemId(box)));
- return items;
- }
- public GrandExchange.Box getBoxForID(int id) {
- return getBox(box -> ge.getItemId(box) == id);
- }
- @Override
- public void initializeModule() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement