public Entity getEntity(Player p, int checkDistance){
Vector one = p.getEyeLocation().clone().getDirection();
Location checkingLoc = p.getEyeLocation().clone();
Entity selectedEntity;
Collection<Entity> collection;
Iterator<Entity> iter;
while(checkDistance >= 0){
collection = checkingLoc.getWorld().getNearbyEntities(checkingLoc, 0.5, 0.5, 0.5);
checkingLoc.add(one);
iter = collection.iterator();
while(iter.hasNext()){
selectedEntity = iter.next();
if(selectedEntity != p){
return selectedEntity;
}
}
checkDistance--;
}
return null;
}