[WorldEdit] Getting the corners of a schematic?

Discussion in 'Plugin Development' started by TheHandfish, Jul 21, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    TheHandfish

    Hello,

    I've been working on pasting schematics. I want to make it so when you try to paste a schematic, it checks if it would have any of its blocks in a world-guard region. Now, the problem is not checking if a location is in a WG region, it's getting the blocks' locations in the first place, before they are even pasted. In other words, the potential locations. Is there any way to do this? Or, is there a better way to check if a schematic, when pasted, will overlap a WG region? Here is what I'm trying:

    Code:Java
    1.  
    2. public void pasteSchematic(World world, File file, Vector origin, Player p) throws DataException, IOException, MaxChangedBlocksException
    3. {
    4. EditSession es = new EditSession(new BukkitWorld(world), 999999999);
    5. CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
    6. if(/*Basically what I'm trying to do is check if the place the whole schematic would be pasted in is in a WG region*/)
    7. {
    8. cc.paste(es, origin, false);
    9. }
    10. else
    11. {
    12. p.sendMessage("§cUnable to place schematic here. It overlaps a WorldGuard region!")
    13. }
    14. }
    15.  

    If possible, I'd also like to make it so it has to be X amount of coordinates away from the WG region, too. Thanks for the help.

    Bump. Still having this issue. Any help?

    I thought up a solution. I'll try it out when I can:

    Code:
    int x = cc.getWidth() / 2;
    int y = cc.getHeight() / 2;
    int z = cc.getLength() / 2;
    
    int px = player.getLocation().getBlockX();
    int py = player.getLocation().getBlockY();
    int pz = player.getLocation().getBlockZ();
    
    for(int scanx = px - x; scanx < px + x, x++)
    {
    for(int scany = py - y; scany < py + y, y++)
    {
    for(int scanz = pz - z; scanz < pz + z, z++)
    {
    if(locationIsInRegion(new Location(world, scanz, scany, scanz))
    {
    // Do something
    }
    else
    {
    // paste
    }
    }
    }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    sk89q

    WG's RegionManager has a getApplicableRegions(ProtectedRegion method) which will do a region overlap check.

    Note: If you have WE/WG/etc. related questions, you can also ask here: http://forum.enginehub.org/
     
    TheHandfish likes this.
  3. Offline

    TheHandfish

    sk89q: (Creator of world/edit responded! :eek:)

    Okay, thanks. I think I have it figured out.
     
Thread Status:
Not open for further replies.

Share This Page