Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Player getNearest(Player p, Double range) {
- double distance = Double.POSITIVE_INFINITY;
- Player target = null;
- for (Entity e : p.getNearbyEntities(range, range, range)) {
- if (!(e instanceof Player)){
- continue;
- }
- if(e == p){
- continue;
- }
- double distanceto = p.getLocation().distance(e.getLocation());
- if (distanceto > distance){
- continue;
- }
- distance = distanceto;
- target = (Player) e;
- }
- return target;
- }
Advertisement
Add Comment
Please, Sign In to add comment