Vinetos

Target Player

Aug 11th, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. public Player getNearest(Player p, Double range) {
  2. double distance = Double.POSITIVE_INFINITY;
  3.  
  4. Player target = null;
  5. for (Entity e : p.getNearbyEntities(range, range, range)) {
  6. if (!(e instanceof Player)){
  7. continue;
  8. }
  9. if(e == p){
  10. continue;
  11. }
  12. double distanceto = p.getLocation().distance(e.getLocation());
  13. if (distanceto > distance){
  14. continue;
  15. }
  16. distance = distanceto;
  17. target = (Player) e;
  18. }
  19. return target;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment