Esempio n. 1
0
  // Nearest Ancient Gate 'to' location (coordinate)
  public static String nearestTo(final WorldCoord coord) {
    String nearestTo = "";
    double shortestDistance = -1;

    for (final Gate gate : Gate.getAll()) {
      if (gate.getTos() == null) continue;

      for (final Location to : gate.getTos()) {
        if (!to.getWorld().equals(coord.getWorld()))
          continue; // We can only be close to gates in the same world

        final double distance = GeometryUtil.distanceBetweenLocations(coord.getLocation(), to);

        if (distance > 10.0) {
          continue;
        }

        if (shortestDistance == -1 || shortestDistance > distance) {
          nearestTo = TeleportUtil.locationToString(to);
          shortestDistance = distance;
        }
      }
    }

    return nearestTo;
  }
Esempio n. 2
0
  // Nearest Ancient Gate - Geometry radius comparison (slow)
  public static Gate nearestGate(
      final WorldCoord coord, final Boolean teleport, final Double radius) {
    Gate nearestGate = null;
    double shortestDistance = -1;

    for (final Gate gate : Gate.getAll()) {
      if (gate.getFroms() == null
          || (gate.getTos() == null && gate.getBungeeTos() == null && teleport == true)) continue;

      // Check the distance between the location and all portal blocks within the gate
      final Set<WorldCoord> portalBlockCoords = gate.getPortalBlocks().keySet();
      if (portalBlockCoords == null) continue;

      for (final WorldCoord blockCoord : portalBlockCoords) {
        if (!blockCoord.getWorld().equals(coord.getWorld()))
          continue; // We can only be close to gates in the same world

        final double distance =
            GeometryUtil.distanceBetweenLocations(coord.getLocation(), blockCoord.getLocation());

        if (distance > radius) continue;

        if (shortestDistance == -1 || shortestDistance > distance) {
          nearestGate = gate;
          shortestDistance = distance;
        }
      }
    }

    return nearestGate;
  }