World Edit API

Discussion in 'Plugin Development' started by Mr. X, Jun 17, 2012.

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

    Mr. X

    i want to use World Edit selctions in my Plugin. But i can't find any informations how.
    Did anyone know how i can get the selction type, the selction corners and how to set the selction?
  2. Offline


    I think on the worldedit github you can find sk89q's source code.
  3. Offline


    I use WorldEdit's API and WorldGuard's API for custom protections.
    Here is an example on what I do to create protected regions in some of my plugins:

    public static void addProtectedRegion(Player player, World world, int x, int y, int z, int radius, int delay, Map flags)
        // get the region manager
        RegionManager rm = worldGuard.getRegionManager(world);
        // make a cuboid with two points to create a 3d cube in the world
        BlockVector b1 = new BlockVector(x + radius + 1, y + radius + 1, z + radius + 1);
        BlockVector b2 = new BlockVector(x - radius - 1, y - radius - 1, z - radius - 1);
        // create the protected region
        ProtectedCuboidRegion pr = new ProtectedCuboidRegion(/* fill in a name here */, b1, b2);
        DefaultDomain dd = new DefaultDomain();
        // add the player to the region
        // set the player as the owner
        // set the flags
        if (flags == null)
            flags = new HashMap();
            flags.put(DefaultFlag.BUILD, State.DENY);
            flags.put(DefaultFlag.CREEPER_EXPLOSIONS, State.DENY);
            //    put more flag definitions here
        catch (Exception exp)
        { }
    And to get the "worldGuard" object, I use this method in my plugin:
    public static WorldGuardPlugin getWorldGuard(JavaPlugin plugin)
        Plugin wPlugin = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
        if ((wPlugin == null) || (!(wPlugin instanceof WorldGuardPlugin)))
            return null;
        return (WorldGuardPlugin) wPlugin;
    Also, make sure you use imports similar to these:
    The code I posted is just an example, and somewhat specific to my uses. I hope this gets you started using thes APIs. :)
    Cowboys1919 likes this.
  4. Offline


    instead of plugin.getServer(), ytou can do Bukkit.getServer(), saves you an argument
  5. Offline


    Ah I see. This will help in future plugins I write. Thanks! :)
  6. Offline

    Mr. X

    Thanks, but how can i do this without World Guard?
  7. Offline


    Derthmonuter likes this.
  8. Offline

    CeramicTitan Retired Staff

    Why would you need to get the plugin onEnable(), couldn't you just add it as an external jar?
  9. Offline


    If I recall correctly, WorldEdit/Guard needs to be loaded as a plugin in order to make use of the API.
    Someone correct me if I'm wrong - it has been a while since I used WorldEdit/Guard.
  10. Offline


     RegionManager rm = WorldGuardPlugin.getRegionManager(world);
    That line shows errors! It says "The method getRegionManager(World) in the type WorldGuardPlugin is not applicable for the arguments (World)"
  11. Offline


    It means that you must use variable "world" with type "World".
    World world = player.getWorld();
Thread Status:
Not open for further replies.

Share This Page