Get blocks in selection WorldEdit

Discussion in 'Plugin Development' started by Emphytos, Apr 11, 2012.

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

    Emphytos

    Hi,

    I want to get all blocks where are in my WorldEdit selection.

    How can I do this please ?

    I realy try a lot of possibility but I don't understand WorldEdit API. x)

    Thanks :)
     
  2. Offline

    puyttre

  3. Offline

    Vecox

    You need the player object of which you want to get the selection. Then it is really simple:

    Code:
    Player p = //get from a command or event or stuff
    WorldEditPlugin worldedit = ... ;//need to get the instance from the PluginManager
    Selection s = worldedit.getSelection(p);
     
    //To get the actual blocks, acquire the coordinates of the corners and iterate:
    Location min = s.getMinimumPoint();
    Location max = s.getMaximumPoint();
     
    //You now have Bukkit types (Location) to work with.
     
  4. Offline

    puyttre

    Vecox
    I got that far but how do you get an ArrayList or ItemStack[] of all the items?
     
  5. Offline

    Vecox

    Ah ok then I misunderstood the problem. Here we go:

    Code:
    //We got the locations now let's get those blocks:
    int xMin = loc1.getBlockX();
    int yMin = loc1.getBlockY();
    int zMin = loc1.getBlockZ();
    //same for loc2 with xMax,yMax and zMax...
     
    ArrayList<Block> blocks = new ArrayList<Block>();
    World w = loc1.getWorld();
     
    for (int i = xMin; i<xMax; i++)
    {
      for (int j = yMin; j<yMax; j++)
      {
          for (int k = zMin; j<zMax; k++)
          {
              blocks.add(w.getBlockAt(i,j,k));
          }
      }
    }
    I hope I got nothing wrong with the variables, but you get the trick :D
     
    puyttre likes this.
Thread Status:
Not open for further replies.

Share This Page