[SOLVED]Help with "Get a WorldEdit Region Selection"

Discussion in 'Plugin Development' started by Syli, Apr 2, 2012.

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



    i have a simple Region selection with pointA and pointB, the command executer says /setPointA and /setPointB, to get the Region, after that the user can execute some code, very Easy.

    So after a while with that Plugin running on my Server, I was asked by a user of if i can hook up the WorldEdit ward functions, to get the Region Selected (because with WorldEditCUI Installed its very easy to get a visual feedback of the Region) and now iam Stuck, because i dont find the two Points in the WorldEdit Plugin and cant extract them after.

    I think the Sulution is very easy but i dont find it.

    So my Question is jus
    How i can get the two Locations (PointA and PointB) from WorldEdit to work with them?!
    and or:
    Is there a good API Documantation from WorldEdit i didn't find with some example Code (i found this oon sk89's site: http://www.sk89q.com/docs/worldedit/api/ but thats just the normal API Doocumentation where i dont find my to Points....)

    Thanks alot

    PS: Sorry for my very bad English, iam from Germany, and afterall English wasn't my favorite in shool! :X
  2. Sorry I don't know because i have WorldEdit too but it works fine.

    You can build with: //set [Blockname]
    //walls [Blockname]

    And the point A+B you can select with item Wooden Axe

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 25, 2016
  3. Offline


    hmm i think i have misswritten the problem, and/or you mussunderstand that problem, its not building ingame with worldedit it is the API for Plugin Devlopment what is my probblem i want to have some kind of code like that:

    onCommand("/someKindOfCommand") {
    Location pointA = worldEditPlugin.MagicWard.getPointA();  //This is what i dont find
    Location pointB = worldEditPlugin.MagicWard.getPointB();  //And this function  too
    if (pointA == null || pointB == null)
    return false; //And an Errorcode that no points are Avalible
    //do somthing with this points

    Regards Syli

    unsolved / small bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 25, 2016
  4. Offline


    onPlayerInteract(Event event)
    Player p = event.getPlayer();
    // do something
  5. Offline


    Husky, thank you thats one way to do it, not that way i want but a way.

    i want to Interact with WorldEdit because you can configure another tool in WorldEdit, like a "Spider Eye" to selecet Regions. but if i go your way, what i think i must do, i have to load the WorldEdit Config file to get the right item for the selection.
    That is a big workaround, i think the better way is to get it directly from WorldEdit. One Way or another i must include WorldEdit in the Projekt file and iam fine with that.

    Edit: another Faktor for get the variables direktly from WorldEdit are the extra commands you can use in WE, like "//expand"
  6. Offline


  7. Offline


    I got this at the house, I can post it later.
    Basically it is under the PlayerInterAct Event.

    goes something like this off top of my head,
    int pos1_x = event.getBlockedClicked().getBlockX();

    I'll post it later if you have not found it.
  8. Offline


    i will test it tomorrow, its very late here and i have to go to bad, thanks man ;)
  9. Offline

    Sir Savary


    I lol'd a little bit at all of the posts in this thread, because they clearly missed what you are trying to accomplish.

    The code to grab WorldEdit and get the region selected by a user is:
    1. WorldGuardPlugin worldGuard = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
    3. try {
    4. WorldEditPlugin worldEdit = worldGuard.getWorldEdit();
    5. } catch (CommandException e) {
    6. e.printStackTrace();
    7. }
    10. Selection sel = worldEdit.getSelection(player);

    I don't know how to get WorldEdit without WorldGuard yet, so you'll have to use the above for the time being. Now, a word of advice when it comes to WorldEdit/WorldGuard API's. The documentation is very lacking, the best way to find something is to figure out which command achieves what you want to do with the API then look at the source for said command and look at how it does it. If that doesn't work, go to the WorldGuard/WorldEdit IRC.

    P.S. To get a region from your Selection, use this
    1. ProtectedRegion region;
    3. DefaultDomain owners = new DefaultDomain();
    5. if (sel instanceof Polygonal2DSelection) {
    6. Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
    7. int minY = polySel.getNativeMinimumPoint().getBlockY();
    8. int maxY = polySel.getNativeMaximumPoint().getBlockY();
    9. region = new ProtectedPolygonalRegion("regionname", polySel.getNativePoints(), minY, maxY);
    10. } else if (sel instanceof CuboidSelection) {
    11. BlockVector min = sel.getNativeMinimumPoint().toBlockVector();
    12. BlockVector max = sel.getNativeMaximumPoint().toBlockVector();
    13. region = new ProtectedCuboidRegion("regionname", min, max);
    14. }
    15. }
    zhuowei likes this.
  10. Offline


    Sir Savary: since WorldEdit is a plugin, why would it be difficult to get it? :p
  11. Offline


    Sir Savary

    Thanks alot, that is what i really needed, Huskys Solution is has the Problem that it isn't "//expand" secured because it checks just the blocks clicked. It is usefull if you ONLY use your Wooden Axe. Its easy to Implement.

    But yours is that what i searched for, now i have the CuboidSelection and can work with it, i think what i missed all the f*****g time was "worldEdit.getSelection(Player plr))" so stupid from me, I don't know why iam missed that, that Method Name is right in my face now....
    I searched for that around 6-8 hours.... sometimes iam just an idiot, its so easy....

    So btw. you dont neead WorldGuard in this code if you only need the Min/Max Points (pointA.X, pointA.Y, pointA.Z and pointB.X, pointB.Y, pointB.), like me. But you need it if you define own Regions with WorldGuard Flags, Owners and Members.

    looks like this is okay for me:
            WorldEditPlugin worldEditPlugin = null;
            worldEditPlugin = (WorldEditPlugin) this.mainPlugin.getServer().getPluginManager().getPlugin("WorldEdit");
            Selection sel = worldEditPlugin.getSelection(plr);
            if (sel instanceof Polygonal2DSelection) {
                    Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
                    int minY = polySel.getNativeMinimumPoint().getBlockY();
                    int maxY = polySel.getNativeMaximumPoint().getBlockY();
            else if (sel instanceof CuboidSelection) {
                BlockVector min = sel.getNativeMinimumPoint().toBlockVector();
                BlockVector max = sel.getNativeMaximumPoint().toBlockVector();


    Regards Syli

    PS: this is "//expand" proofed
  12. Offline

    Sir Savary

    I figured out how to do without WorldGuard shortly after I posted, and you're welcome.
  13. Offline


    these threads are gold, worldedit is seriously a challenge sometimes.
  14. Offline


    Could you upload the project file so I can understand how WorldEdit is exactly implemented in your plugin?
  15. Offline


    Could someone post how they used these BlockVecotrs and PolygonalSelection stuff to change blocks into other things?
    Sir Savary
  16. Offline


    This thread is 2 years old and the 2 people you tagged has not been on for a long time now(you can see from their profile pages). Instead of bumping a dead thread, you can post a new thread with your question.
    Zandor300 and XDdrummer like this.
Thread Status:
Not open for further replies.

Share This Page