Solved How to change 1 type of block in wg region

Discussion in 'Plugin Development' started by FrozenLegend, May 26, 2016.

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

    FrozenLegend

    Hi everyone i wanted to know if it's possible to change 1 type of block in worldguard region
    (exemple : change every white wool into redwool in the region.)
    And if it's possible how to do that ?

    Thanks !
     
  2. Code:
    //replace 35 35:14
    should work. (oh you can of course use wool instead of 35, I just prefer ids :p)
     
  3. Offline

    FrozenLegend

    I want to know how to do in Java not with commands x)
     
  4. Offline

    CoolDude53

    @FrozenLegend If you are talking about doing so through your code you're in luck, I just implemented something similar.

    Code:
    // get your desired region from world guard (getWorldGuard() is a method I wrote to get the world guard plugin instance)
    ProtectedRegion region = getWorldGuard().getRegionManager(world).getRegion("desired_region");
    
    // create a world edit region using the min and max points of your world guard region, not sure if this is the best way to do it, but it works
    CuboidRegion test = new CuboidRegion(new BukkitWorld(world), region.getMinimumPoint(), region.getMaximumPoint());
    
    // create an edit session, which allows you to edit blocks in your desired world
    EditSession editSession = new EditSession(new BukkitWorld(desiredWorld), getWorldEdit().getWorldEdit().getConfiguration().maxChangeLimit);
    
    // here you create a set of world edit blocks that you wish to replace
    Set<BaseBlock> toReplace = new HashSet<>();
    toReplace.add(new BaseBlock(35, 0));
    
    // now use that edit session to replace the blocks in toReplace with your desired block
    try
    {
         editSession.replaceBlocks(test, toReplace, new BaseBlock(35, 14));
    } catch (MaxChangedBlocksException e)
    {
         e.printStackTrace();
    }
     
  5. Offline

    FrozenLegend

    @CoolDude53 Men ... I love you ! Works fine and the comments help me alot.
    Thanks men !
    And u know how to get the region where the player is ?
     
  6. Offline

    I Al Istannen

    @FrozenLegend
    Here. The examples "Getting region at (x,y,z)". There are multiple ways.
     
  7. Offline

    WolfMage1

    Really wish this was added earlier xD
     
Thread Status:
Not open for further replies.

Share This Page