Solved Setting WorldEdit selection to air

Discussion in 'Plugin Development' started by Blockhead7360, Aug 29, 2015.

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

    Blockhead7360

    Hello!

    I am making a minigame plugin, and after the game, I am supposed to use the WorldEdit selection (saved in config) to set everything in the arena to air. How would I do that? I know how to get the selection from the config, but I do not know how to set everything in it to air.

    Please help anyone, thanks :D
     
  2. Offline

    caderape

    @Blockhead7360
    Get the minimum point and the maximum point.
    Do a loops for x y z, check if the block is not air, then set to air.
     
  3. Offline

    Blockhead7360

    @caderape I did this:
    Code:
    int xMin = getConfig().getInt("arena." + arena + ".blockspawn.low.x");
            int yMin = getConfig().getInt("arena." + arena + ".blockspawn.low.y");
            int zMin = getConfig().getInt("arena." + arena + ".blockspawn.low.z");
           
            World w = getServer().getWorld(getConfig().getString("arena." + arena + ".blockspawn.low.world"));
           
            int xMax = getConfig().getInt("arena." + arena + ".blockspawn.high.x");
            int yMax = getConfig().getInt("arena." + arena + ".blockspawn.high.y");
            int zMax = getConfig().getInt("arena." + arena + ".blockspawn.high.z");
           
            for (int x = xMin; x < xMax; x++){
                for (int y = yMin; x < yMax; y++){
                    for (int z = zMin; x < zMax; z++){
                        if (w.getBlockAt(new Location(w, x, y, z)).getType() != Material.AIR) w.getBlockAt(new Location(w, x, y, z)).setType(Material.AIR);
                       
                   
                    }
                }
            }
    However, whenever this code is run, my server times out! Why?
     
  4. Install aSyncWorldEdit :p
     
  5. Offline

    Blockhead7360

  6. Well, if worldedit crashes you now. Yes.
     
  7. @Blockhead7360 @TheGamesHawk2001
    It usually times out due to an incorrect loop, and look:
    for (int x = xMin; x < xMax; x++){
    for (int y = yMin; x < yMax; y++){
    for (int z = zMin; x < zMax; z++){
    That is an incorrect loop!
     
  8. Offline

    Blockhead7360

    @megamichiel oh wow. (facepalm)

    Let me test it out the CORRECT way, and see if it works

    @megamichiel It didn't work for some reason. Here is my code:
    Code:
    for (int x = xMin; x < xMax; x++){
                for (int y = yMin; y < yMax; y++){
                    for (int z = zMin; z < zMax; z++){
                        if (w.getBlockAt(new Location(w, x, y, z)).getType() != Material.AIR) w.getBlockAt(new Location(w, x, y, z)).setType(Material.AIR);
                       
    
                    }
                }
            }
    It looks like it does some of the area, but not all of it... No errors produced.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  9. Offline

    caderape

  10. Offline

    Blockhead7360

    @caderape Yup! It's working! Thanks for everyone's help, and I will mark this as solved ;)
     
Thread Status:
Not open for further replies.

Share This Page