Sin 0 Share Posted October 15, 2015 (edited) import java.util.Optional; import java.util.function.Predicate; public class Target<T> { private T target; private Searcher<T> searcher; private Predicate<T> validity; public Target(Predicate<T> validity, Searcher<T> searcher) { this.validity = validity; this.searcher = searcher; } public T get() { return this.target; } public void set(T target) { this.target = target; } public boolean valid() { return this.valid(this.validity); } public boolean valid(Predicate validity) { if(validity.test(this.target)) { return true; } else { this.target = null; return false; } } public boolean find() { Optional optional = this.searcher.search(); if(optional.isPresent()) { this.target = (T)optional.get(); return true; } else { return false; } } } import java.util.Comparator; import java.util.Optional; import java.util.function.Predicate; /** you will need to import the DreamBot API for the following and change thier respected variables (this is from another script client i used) import Entity; import Item; import NPC; import Player; **/ public interface Searcher<T> { //some different API but will need changing Optional<T> search(); static Searcher<NPC> closestNPC(BasicScript bs, EntityDefinition definition) { return () -> { return bs.getNPCStream().filter(definition).min(new Comparator<NPC>() { public int compare(NPC a, NPC { return bs.getMap().distance(a.getPosition()) - bs.getMap().distance(b.getPosition()); } }); }; } static Searcher closestObject(BasicScript bs, EntityDefinition definition) { return () -> { return bs.getObjectStream().filter(definition).min(new Comparator<Entity>() { public int compare(Entity a, Entity { return bs.getMap().distance(a.getPosition()) - bs.getMap().distance(b.getPosition()); } }); }; } static Searcher closestGroundItem(BasicScript bs, EntityDefinition definition) { return () -> { return bs.getGroundItemStream().filter(definition).min(new Comparator<Entity>() { public int compare(Entity a, Entity { return bs.getMap().distance(a.getPosition()) - bs.getMap().distance(b.getPosition()); } }); }; } static Searcher<Player> anyPlayer(BasicScript bs, Predicate<Player> predicate) { return () -> { return bs.getPlayerStream().filter(predicate).findAny(); }; } static Searcher<Item> anyInventoryItem(BasicScript bs, Predicate<Item> predicate) { return () -> { return bs.getInventoryStream().filter(predicate).findAny(); }; } } I have more stuff to add but I have to go Edited October 15, 2015 by Sin Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now