WorldGuard ProtectedPolygonRegion Getting Blocks

Discussion in 'Spigot Plugin Development' started by Cloaking_Ocean, Apr 15, 2017.

  1. Hello, Spigot!
    Today I'm in need of being able to get the blocks of a defined worldguard region. I'm attempting to get the blocks for a cuboid region by looping through a regions height, length, and width. However, I haven't found any way of getting the blocks for a polygonal region.

    From the WorldGuard API it shows:
    [​IMG]

    From here it leaves me with a List of BlockVector2D objects. I'm not sure what to do with these.
    I attempted to create a WorldEdit Selection from the points, and see if I could get the blocks that way:

    Code (Text):
    if (region instanceof ProtectedPolygonalRegion) {
        ProtectedPolygonalRegion polygon = (ProtectedPolygonalRegion) region;
        List<BlockVector2D> points = polygon.getPoints();
     
        Polygonal2DRegion weRegion = new Polygonal2DRegion(
                Bukkit.getServer().getWorld("world"),
                polygon.getPoints(),
                polygon.getMinimumPoint().getBlockY(),
                polygon.getMaximumPoint().getBlockY());
    }

    However, I get this compile error from eclipse: "The constructor Polygonal2DRegion(World, List<BlockVector2D>, int, int) is undefined".

    Yes I know what this error is stating (There's no constructor with those specific parameters), however when I use Eclipse's autocomplete feature it shows me there's an option for a constructor with one world, a set of points, and two ints.

    [​IMG]

    I'm not sure what the "points" refer to either.
    Any help is greatly appreciated!
     
  2. Hello

    First of all, this is a well formatted question!
    Second thing is, I am quite sure that these BlockVector2D's contain all of the necessary data to work with. I guess you can just loop through the list with a foreach statement. In that foreach, you can access the data of the current element given by the foreach. That's just 2d data however, inside of that foreach, create another foreach which loops through the Y-coordinates!
    https://docs.sk89q.com/worldedit/apidocs/com/sk89q/worldedit/BlockVector2D.html

    Good luck.
     
  3. Thank you for your compliment and for your help.

    I'm still a little confused about how looping through all the y values for each point gets a polygon region.

    Either way, this is the code I have now:

    Code (Text):
    if (region instanceof ProtectedPolygonalRegion) {
        ProtectedPolygonalRegion polygon = (ProtectedPolygonalRegion) region;
        List<BlockVector2D> points = polygon.getPoints();
     
        for (BlockVector2D point : points) {
            for (int y = polygon.getMinimumPoint().getBlockY(); y < polygon.getMaximumPoint().getBlockY(); y++) {
                blocks.add(new Location(Bukkit.getServer().getWorld("world"), point.getBlockX(), y, point.getBlockZ())); //TODO: Replace with name of world used on server.
            }
        }
     
    }
    I haven't been able to test it yet, but I was just looking for confirmation that this is what you were trying to explain to me. Once I'm able to test it and verify it, I'll update this thread.
     
  4. That seems like a good try! If I am not mistaking, Polygons here always use x and z as their base and y as the height, with y being the same for every other x and y combination.
    If it does not work, feel free to tell me, I can try to play around with it.