/** Checks to see if a point is inside this region. */
  @Override
  public boolean contains(Vector pt) {
    int targetX = pt.getBlockX(); // wide
    int targetY = pt.getBlockY(); // height
    int targetZ = pt.getBlockZ(); // depth

    if (targetY < minY || targetY > maxY) {
      return false;
    }
    // Quick and dirty check.
    if (targetX < min.getBlockX()
        || targetX > max.getBlockX()
        || targetZ < min.getBlockZ()
        || targetZ > max.getBlockZ()) {
      return false;
    }
    boolean inside = false;
    int npoints = points.size();
    int xNew, zNew;
    int xOld, zOld;
    int x1, z1;
    int x2, z2;
    int i;

    xOld = points.get(npoints - 1).getBlockX();
    zOld = points.get(npoints - 1).getBlockZ();

    for (i = 0; i < npoints; i++) {
      xNew = points.get(i).getBlockX();
      zNew = points.get(i).getBlockZ();
      // Check for corner
      if (xNew == targetX && zNew == targetZ) {
        return true;
      }
      if (xNew > xOld) {
        x1 = xOld;
        x2 = xNew;
        z1 = zOld;
        z2 = zNew;
      } else {
        x1 = xNew;
        x2 = xOld;
        z1 = zNew;
        z2 = zOld;
      }
      if ((xNew < targetX) == (targetX <= xOld)
          && ((long) targetZ - (long) z1) * (long) (x2 - x1)
              <= ((long) z2 - (long) z1) * (long) (targetX - x1)) {
        inside = !inside;
      }
      xOld = xNew;
      zOld = zNew;
    }

    return inside;
  }
Пример #2
0
 public void showInfo(CommandSender sender) {
   StringBuilder sb = new StringBuilder();
   Iterator<String> ite = members.iterator();
   while (ite.hasNext()) {
     sb.append(ite.next());
     if (ite.hasNext()) {
       sb.append(", ");
     }
   }
   String pos =
       "("
           + pos1.getBlockX()
           + ", "
           + pos1.getBlockY()
           + ", "
           + pos1.getBlockZ()
           + ") => "
           + "("
           + pos2.getBlockX()
           + ", "
           + pos2.getBlockY()
           + ", "
           + pos2.getBlockZ()
           + ")";
   sender.sendMessage(
       Config.getMessage(
           "infoWioska",
           akronim,
           nazwa,
           leader,
           sb.toString(),
           world,
           pos,
           getEstimated(),
           getExpired()));
 }
Пример #3
0
  @Override
  public boolean equals(Object obj) {
    if (obj instanceof ChunkVector) super.equals(obj);

    return false;
  }
  /**
   * Checks if the bounding box of a region intersects with with the bounding box of this region.
   *
   * @param region the region to check
   * @return whether the given region intersects
   */
  protected boolean intersectsBoundingBox(ProtectedRegion region) {
    BlockVector rMaxPoint = region.getMaximumPoint();
    BlockVector min = getMinimumPoint();

    if (rMaxPoint.getBlockX() < min.getBlockX()) return false;
    if (rMaxPoint.getBlockY() < min.getBlockY()) return false;
    if (rMaxPoint.getBlockZ() < min.getBlockZ()) return false;

    BlockVector rMinPoint = region.getMinimumPoint();
    BlockVector max = getMaximumPoint();

    if (rMinPoint.getBlockX() > max.getBlockX()) return false;
    if (rMinPoint.getBlockY() > max.getBlockY()) return false;
    if (rMinPoint.getBlockZ() > max.getBlockZ()) return false;

    return true;
  }
 /**
  * Check to see if a position is contained within this region.
  *
  * @param position the position to check
  * @return whether {@code position} is in this region
  */
 public boolean contains(BlockVector2D position) {
   checkNotNull(position);
   return contains(new Vector(position.getBlockX(), min.getBlockY(), position.getBlockZ()));
 }
  @Override
  public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions)
      throws UnsupportedIntersectionException {
    int numRegions = regions.size();
    int numPoints = points.size();
    List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
    int i, i2, i3;

    for (i = 0; i < numRegions; i++) {
      ProtectedRegion region = regions.get(i);
      BlockVector rMinPoint = region.getMinimumPoint();
      BlockVector rMaxPoint = region.getMaximumPoint();

      // Check whether the region is outside the min and max vector
      if ((rMinPoint.getBlockX() < min.getBlockX() && rMaxPoint.getBlockX() < min.getBlockX())
          || (rMinPoint.getBlockX() > max.getBlockX() && rMaxPoint.getBlockX() > max.getBlockX())
              && ((rMinPoint.getBlockY() < min.getBlockY()
                      && rMaxPoint.getBlockY() < min.getBlockY())
                  || (rMinPoint.getBlockY() > max.getBlockY()
                      && rMaxPoint.getBlockY() > max.getBlockY()))
              && ((rMinPoint.getBlockZ() < min.getBlockZ()
                      && rMaxPoint.getBlockZ() < min.getBlockZ())
                  || (rMinPoint.getBlockZ() > max.getBlockZ()
                      && rMaxPoint.getBlockZ() > max.getBlockZ()))) {
        intersectingRegions.add(regions.get(i));
        continue;
      }

      // Check whether the regions points are inside the other region
      for (i2 = 0; i < numPoints; i++) {
        Vector pt = new Vector(points.get(i2).getBlockX(), minY, points.get(i2).getBlockZ());
        Vector pt2 = new Vector(points.get(i2).getBlockX(), maxY, points.get(i2).getBlockZ());
        if (region.contains(pt) || region.contains(pt2)) {
          intersectingRegions.add(regions.get(i));
          continue;
        }
      }

      // Check whether the other regions points are inside the current region
      if (region instanceof ProtectedPolygonalRegion) {
        for (i2 = 0; i < ((ProtectedPolygonalRegion) region).getPoints().size(); i++) {
          BlockVector2D pt2Dr = ((ProtectedPolygonalRegion) region).getPoints().get(i2);
          int minYr = ((ProtectedPolygonalRegion) region).minY;
          int maxYr = ((ProtectedPolygonalRegion) region).maxY;
          Vector ptr = new Vector(pt2Dr.getBlockX(), minYr, pt2Dr.getBlockZ());
          Vector ptr2 = new Vector(pt2Dr.getBlockX(), maxYr, pt2Dr.getBlockZ());

          if (this.contains(ptr) || this.contains(ptr2)) {
            intersectingRegions.add(regions.get(i));
            continue;
          }
        }
      } else if (region instanceof ProtectedCuboidRegion) {
        BlockVector ptcMin = region.getMinimumPoint();
        BlockVector ptcMax = region.getMaximumPoint();

        if (this.contains(new Vector(ptcMin.getBlockX(), ptcMin.getBlockY(), ptcMin.getBlockZ()))
            || this.contains(new Vector(ptcMin.getBlockX(), ptcMin.getBlockY(), ptcMax.getBlockZ()))
            || this.contains(new Vector(ptcMin.getBlockX(), ptcMax.getBlockY(), ptcMax.getBlockZ()))
            || this.contains(new Vector(ptcMin.getBlockX(), ptcMax.getBlockY(), ptcMin.getBlockZ()))
            || this.contains(new Vector(ptcMax.getBlockX(), ptcMax.getBlockY(), ptcMax.getBlockZ()))
            || this.contains(new Vector(ptcMax.getBlockX(), ptcMax.getBlockY(), ptcMin.getBlockZ()))
            || this.contains(new Vector(ptcMax.getBlockX(), ptcMin.getBlockY(), ptcMin.getBlockZ()))
            || this.contains(
                new Vector(ptcMax.getBlockX(), ptcMin.getBlockY(), ptcMax.getBlockZ()))) {
          intersectingRegions.add(regions.get(i));
          continue;
        }
      } else {
        throw new UnsupportedOperationException("Not supported yet.");
      }

      // Check whether the current regions edges collide with the regions edges
      boolean regionIsIntersecting = false;
      for (i2 = 0; i2 < numPoints; i2++) {
        boolean checkNextPoint = false;
        BlockVector2D currPoint = points.get(i2);
        BlockVector2D nextPoint;

        if (i2 == (numPoints - 1)) {
          nextPoint = points.get(0);
        } else {
          nextPoint = points.get(i2 + 1);
        }

        int currX = currPoint.getBlockX();
        int currZ = currPoint.getBlockZ();

        while (!checkNextPoint) {
          for (i3 = this.minY; i3 <= this.maxY; i3++) {
            if (region.contains(new Vector(currX, i3, currZ))) {
              intersectingRegions.add(regions.get(i));
              regionIsIntersecting = true;
              break;
            }
          }

          if (currX == nextPoint.getBlockX()
              || currZ == nextPoint.getBlockZ()
              || regionIsIntersecting) {
            checkNextPoint = true;
          }

          if (nextPoint.getBlockX() > currPoint.getBlockX()) {
            currX++;
          } else {
            currX--;
          }
          if (nextPoint.getBlockZ() > currPoint.getBlockZ()) {
            currZ++;
          } else {
            currZ--;
          }
        }

        if (regionIsIntersecting) {
          break;
        }
      }
    }

    return intersectingRegions;
  }
Пример #7
0
  public static void editPlotSign(
      Player player, String zone, String number, ProtectedRegion region) {
    String line1 = "######";
    String line2 = zone + " Zone - " + number;
    String line3 = player.getName();
    String line4 = "######";

    World world = player.getWorld();

    BlockVector max = region.getMaximumPoint();
    BlockVector min = region.getMinimumPoint();

    int minx = Math.min(max.getBlockX() + 1, min.getBlockX() - 1),
        miny = Math.min(max.getBlockY() + 1, min.getBlockY() - 1),
        minz = Math.min(max.getBlockZ(), min.getBlockZ()),
        maxx = Math.max(max.getBlockX() + 1, min.getBlockX() - 1),
        maxy = Math.max(max.getBlockY() + 1, min.getBlockY() - 1),
        maxz = Math.max(max.getBlockZ(), min.getBlockZ());
    int a = 0;
    for (int x = minx; x <= maxx; x++) {
      for (int y = miny; y <= maxy; y++) {
        for (int z = minz; z <= maxz; z++) {
          a++;
          Block b = world.getBlockAt(x, y, z);
          if (b.getType().equals(Material.SIGN_POST)
              || b.getType().equals(Material.WALL_SIGN)
              || b.getType().equals(Material.SIGN)) {
            Sign sign = (Sign) b.getState();
            if (sign.getLine(0).contains("#")) {
              sign.setLine(0, line1);
              sign.setLine(1, line2);
              sign.setLine(2, line3);
              sign.setLine(3, line4);
              sign.update(true);

              player.sendMessage("yes");
            } else {
              player.sendMessage("no");
            }
            break;
          }
        }
      }
    }
    player.sendMessage("Number: " + a);
  }