Beispiel #1
0
  /**
   * Returns the nearest object from the local player which satisfies the filter
   *
   * @param filter The filter to accept objects, can be null
   * @return The nearest object
   */
  public GameObject getNearest(Filter<GameObject> filter) {
    GameObject[] objects = getAll(null, TYPE_ALL);
    GameObject nearest = null;
    Actor player = ctx.players.getLocalPlayer();
    for (GameObject obj : objects) {
      if (obj == null) continue;

      if (nearest == null
          || (player.getLocation().distanceTo(obj.getLocation())
                  < player.getLocation().distanceTo(nearest.getLocation())
              && (filter == null || filter.accept(obj)))) {
        nearest = obj;
      }
    }
    return nearest;
  }