Using the WorldEdit API (Edit session - bug?)

Discussion in 'Plugin Development' started by victorhjelmberg, Mar 30, 2022.

  1. Offline

    victorhjelmberg

    [UPDATE - FIXED]
    Turned out that all i had to do was call myEditSesssion.close(). It was pure luck that i found it.

    Hello. I'm new to making plugins, but i have some experience in Java.

    I'm currently working on a plugin, that enables you to make mines. It is essential to be able to use the WorldEdit selection when making mines.

    I have written the following code, that would activate when a command is called:

    Code:
        private void testMine(CommandSender sender, Command command, String label, String[] args){
            Player p = (Player) sender;
    
            try { //Fails if no selection has been made
                LocalSession currentLocalSession = WorldEdit.getInstance().getSessionManager().findByName(p.getName());
                Region localRegion = currentLocalSession.getSelection(currentLocalSession.getSelectionWorld());
    
                try{
    
                    EditSession myEditSession = WorldEdit.getInstance().newEditSession(currentLocalSession.getSelectionWorld());
    
                    BlockState stone = BukkitAdapter.adapt(Material.STONE.createBlockData());
                    myEditSession.setBlocks(localRegion, stone);
    
                    p.sendMessage("No exceptions");
                } catch (Exception e){
                    p.sendMessage(e.toString());
                }
            } catch (Exception e){
                p.sendMessage("Error: No selection has been made");
            }
        }
    The code runs without errors, and without exceptions, and reaches p.sendMessage("No exceptions"), but i don't experience any results. What am i doing wrong?

    Thanks in advance :)

    [UPDATE - FIXED]
    Turned out that all i had to do was call myEditSesssion.close(). It was pure luck that i found it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 30, 2022
  2. Offline

    Smeary_Subset

    Make sure to mark this as solved since you figured it out
     

Share This Page