by

WorldEdit selections for Bukkit plugins

WorldEdit provides an easy-to-use API for Bukkit plugins to access the player’s current region selection.

A large part of WorldEdit uses an abstract internal API for easy portability  For your convenience, we provide a Bukkit-native selection API that makes it easier to work with that part of WorldEdit. It is possible to “reach through” to access to the internal features of WorldEdit, but if you are interested in only getting selections, that shouldn’t be needed.

Getting a selection

To get a selection, you need to:

  1. Get a reference to WorldEditPlugin from Bukkit’s plugin manager.
  2. Cast the reference from JavaPlugin to a more specific WorldEditPlugin.
  3. Get the selection by calling getSelection().

See the snippet below.

Remember that the user may not have a selection yet, in which case, you need to detect it and notify the user.

What kind of shape?

Selections may be cuboids — that is, they may be boxes aligned to the world. However, they may also be 2D polygons extruded vertically. Depending on your use case, you may not care (you can just get the min/max points), but if you do, the selection object returned is actually one of a more specific kind. By using “instanceof,” you can detect which kind of shape it is and act accordingly.

Be aware that new shapes may be added in the future and you need to be aware of changes.

Proper dependencies

If you are using WorldEdit with your plugin, you may need to require that WorldEdit be loaded before your plugin. That way, you can guarantee that it’s available when your plugin is loaded. There are two kind of dependencies supported by Bukkit: a hard dependency, that requires WorldEdit to be installed for your plugin to load, or a soft one, where the loader will try its best to load your plugin at the end, but will continue if the soft dependencies are not found.

The following would go into your plugin.yml for a hard dependency.

In the case of soft dependencies, you can specify it as so:

Be aware that the call to getPlugin() in the first snippet may return null if you are using a soft dependency.

API stability

We don’t expect to change any of this any time soon, which means you won’t have to figure out why your plugin broke because of WorldEdit! It won’t break when MC versions change either.

  • Shzylo

    I am running on Java 7, and When I enter this code, I come out with errors, so I reformatted my code to the following:
    http://pastebin.com/FzzW7JRz

    and these are the errors I get:
    http://pastebin.com/PwjKJSjx

    I know what those errors mean, but I don’t know how to use them.

    • http://www.sk89q.com sk89q

      Those are actually warnings, so you can ignore them.

      They are basically saying that you set “a = 3″ but then you never actually use “a” anywhere (in this case, the variables cuboid, min, max, and world).

  • SanJay

    I won’t to import worldedit schematics in a plugin. What shoud i do?

    • SanJay

      Want *

  • http://drtl.tumblr.com/ Isaac Moore

    Does getSelection() return null if the player does not yet have a selection?

    • http://www.sk89q.com sk89q

      Yes

      • http://drtl.tumblr.com/ Isaac Moore

        Thanks!

        • eleectricman226

          If the player only has one selected point, does it still return null?

          • http://www.sk89q.com sk89q

            Yes. It’s considered “no selection.”

  • DJF1234567890

    Thank you this really helped me to continue on with my plugin. Thanks a lot!

  • Paulomart

    Can you load schematic’s and paste via API?

  • jdon

    Hey, is there a way to create a selection using the api ?

  • Artem

    I have a minecraft server. I want to allow any player to use //wand command. Please help me do this. I found this command:

    public Selection getSelection(org.bukkit.entity.Player player)

    Gets the region selection for the player.

    Parameters:player – Returns:the selection or null if there was nonewhere do I have to put this command?

  • http://xesau.eu/ Xesau

    WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin(“WorldEdit”);
    Selection selection = worldEditPlugin.getSelection(player);

    This wont work because worldEditPlugin is not defined, only worldEdit

    :)

  • katie

    I still don’t get how to load it on my computer so I can use it

  • stive elarbiti

    i can’t download worldedit

    • Hayden ‘Echo’ A.

      Neither can I! The forum says this link is where the download for the newest versions is. However, it only takes me to this page…

  • Crinkh

    So, am i able to acces .def files with this? Cause a server mod i’m using is using .def files for templates.

    • http://www.sk89q.com sk89q

      No. I’m not familiar with the .def format.

      • Crinkh

        Thanks for the answer tho <3

  • Micah

    How do I set it to where I can limit the blocks for worldEdit? cause people keep overloading the server and greifing it, so how do you do that?

  • ben

    hi

  • ben

    hi can someone make me admin beacuse pepol all way grif my plot and every one dont lisen to me and im sure that if you make me admin rushnet you will be happy you will not be sad and if yes saw thanks alot and if no saw ok

  • KINGNEVER

    hi

  • snook

    i cant use it eathir and i rage quited

  • Mike

    I got WorldEdit by Voting, but i type in /worldedit and it gives me: /we: (ci,tz,version). What do i do?