Proper usage of WorldEdit API

Discussion in 'Plugin Development' started by bitWolfy, Feb 3, 2013.

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

    bitWolfy

    Hello, ladies and gentlemen.

    I have a really awkward question to ask. How do you properly use WorldEdit for region selection in a plugin? Do not misunderstand - I am already using it, and it works, but it has a very annoying glitch.

    Here is my code to fetch the selection points for the player:

    Code:
        public static Location[] getPoints(Player player) {
            WorldEditPlugin we = PrisonSuite.getWorldEditPlugin();
            Region sel = null;
            LocalSession session = we.getSession(player);
            try { sel = session.getSelection(session.getSelectionWorld()); }
            catch (IncompleteRegionException ire) { return null; }
            Location[] loc = {null, null};
            if(sel == null) return null;
            loc[0] = toLocation(player.getWorld(), sel.getMinimumPoint());
            loc[1] = toLocation(player.getWorld(), sel.getMaximumPoint());
            return loc;
        }
    
    At this point, WorldEditPlugin has already been declared in the main class like so:

    Code:
    worldEditPlugin = (WorldEditPlugin) this.getServer().getPluginManager().getPlugin("WorldEdit");
    
    I check if WorldEdit is actually enabled on the server through a different method. This code works; I receive two points from WorldEdit. Unfortunately, they are not always the correct points.

    For example, I may select two points with WorldEdit, then save the region with my own plugin. After that, I select another region with WE, and save it, however, the selection is sometimes the same as it was back when I was selecting the first region.

    The problem is not consistent, sometimes it happens, sometimes it does not. Has anyone else encountered this problem, and if you have, what are the possible solutions for it?

    bitWolfy

    Any suggestions?

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

    raGan.

    It is very strange. Could error possibly be somewhere else ? I believe that identifying when exactly this happen is crucial here.
     
  3. Offline

    bitWolfy

    I think that this has something to do with the fact that I get the selection from player's LocalSession. Maybe, it is not being updated with the new selection in time?..

    There is nothing that can cause an error after that. I am saving the region almost immediately after getting it from WorldEdit, and there are no problems if I select the region with my own commands instead of WorldEdit.
     
  4. Offline

    raGan.

    You can try scheduling repeating task that checks your selection to see whether session is causing problem or not.
     
  5. Offline

    Gildan27

    I use worldEditPlugin.getSelection(player) to get the selection, instead of using a LocalSession, like so:

    Code:
    Player player = getSomePlayer();
    WorldEditPlugin worldEditPlugin = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
    Selection selection = worldEditPlugin.getSelection(player);
    I've never had any problems doing it this way.
     
  6. Offline

    bitWolfy

Thread Status:
Not open for further replies.

Share This Page