Solved How to use WorldEdit Api?

Discussion in 'Plugin Development' started by John Cameron, Apr 24, 2013.

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

    John Cameron

    Hello!

    I need help on the following questions:

    How do I use the WorldEdit API?

    Next thing is that, how do I get every block inside a region when selected?

    Thanks! :)
     
  2. Offline

    chasechocolate

  3. Offline

    John Cameron

    Ok thanks, but how do I use it?
     
  4. Offline

    chasechocolate

    John Cameron Create a WorldEditPlugin variable, and on the onEnable() check if the plugin "WorldEdit" is installed on the server, and if it is pass a casted value into the variable. Then you can get the selection by using Selection selection = <WorldEditPlugin Variable>.getSelection(player) where the stuff in the <> is your variable. Then, loop through the blocks in selection.getNativeMinimumPoint() and selection.getNativeMaximumPoint().
     
    FletchTech90 and John Cameron like this.
  5. Offline

    John Cameron

    Awesome Thanks! :D

    Here is the code for the next generation ;)

    Code:
      WorldEditPlugin worldEditPlugin = null;
                    worldEditPlugin = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
                    if(worldEditPlugin == null){
                        player.sendMessage("Error with region undoing! Error: WorldEdit is null.");   
                    }
                    Selection sel = worldEditPlugin.getSelection(player);
           
                    if (sel instanceof CuboidSelection) {
                        Vector min = sel.getNativeMinimumPoint();
                        Vector max = sel.getNativeMaximumPoint();
                        for(int x = min.getBlockX();x <= max.getBlockX(); x=x+1){
                            for(int y = min.getBlockY();y <= max.getBlockY(); y=y+1){
                                for(int z = min.getBlockZ();z <= max.getBlockZ(); z=z+1){
                                    Location tmpblock = new Location(player.getWorld(), x, y, z);
                                    tmpblock.getBlock().setType(Material.AIR); //Just For debug
                                }
                            }
                        }
                        player.sendMessage(ChatColor.AQUA + "Undo Complete!");
                    }else{
                        player.sendMessage(ChatColor.DARK_RED + "Invalid Selection!");
                    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page