Solved World Edit Issue

Discussion in 'Plugin Development' started by Coopah, Jan 3, 2016.

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

    Coopah

    I have a method which pastes a schematic, however, later on I want to undo the schematic.
    The issue is, the player isn't pasting the schematic, so I can't actually use the undo() feature.
    My question is, how do I get the original blocks? All the blocks that have been replaced with the schematic?

    Code:
    Code:
    public static void PasteSchematic(String Schematic, Location x){
    
            File file = new File("plugins/WorldEdit/schematics/" + Schematic + ".schematic");
    
            try {
    
                Vector v = new Vector(x.getBlockX(), x.getBlockY(), x.getBlockZ());
                BukkitWorld BWf = new BukkitWorld(x.getWorld());
                EditSession es = new EditSession(BWf, 2000000);
                CuboidClipboard c1 = SchematicFormat.MCEDIT.load(file);
                c1.place(es, v, false);
    
            } catch (DataException ex) {
            } catch (IOException ex) {
            } catch (MaxChangedBlocksException ex) {
    
            }
    
        }
     
  2. Offline

    mcdorli

    Don't catch anything without doing something with that information, that's a terrible idea.
     
  3. Offline

    Coopah

    @mcdorli
    How would I get the blocks with the information then?
     
  4. Offline

    teej107

    @Coopah Have you looked at WorldEdit's API documentation? I'm fairly certain it has a method to get/tie an EditSession from a Player. (or similar so you can use /undo)
     
  5. Offline

    Coopah

    @teej107
    Yes however, a player isn't pasting the schematic. I believe EditSessions only acquires a Player's session.
    Basically I just need to get all the blocks that are going to be affected by the schematic. I know what to do from there. So how would I do this?
     
    Last edited: Jan 4, 2016
  6. Offline

    Coopah

    Bump
     
  7. Offline

    Coopah

    Bump..
     
  8. Offline

    teej107

     
  9. Offline

    Coopah

    @teej107
    I don't believe you can achieve what I want using World Edit's api.
     
  10. Offline

    teej107

    WorldEdit can do it so you should be able to as well.
     
  11. Offline

    Coopah

    @teej107
     
  12. Offline

    teej107

    Please go into detail of what you mean by that. Because I have used WorldEdit's paste command and been able to use the undo command to undo the paste in game.
     
  13. Offline

    Areoace

    He's trying to make a plugin to spawn world events, e.g spawn a structure with mobs spawning on it, but he needs to use worldedit to spawn and unspawn the structure @teej107
     
  14. Offline

    Coopah

    @Areoace
    Precisely.
    @teej107
    I'm pasting the schematic in and not setting a session because a player isn't pasting it.
    I want to be able to undo the paste or remove the structure without assigning a session to a player.
     
  15. Offline

    teej107

  16. Offline

    Coopah

    @teej107
    Then what do I store in the EditSession and how do I check it? It requires a player, correct?
     
  17. Offline

    teej107

    @Coopah I'm not saying this will work but to try it.
    Save your EditSession for later.
    when you are ready to undo, just call the undo method on the saved EditSession supplying the saved EditSession in the parameters. It's very odd to call a method on an Object passing itself in the parameters which is why I'm not sure it'll work but it's worth a shot.
     
  18. Offline

    Coopah

    @teej107
    Getting a session takes a player, this won't be applicable.
    Code:
    EditSession es = Methods.getWorldEdit().getSession(2000000);
    
     
  19. Offline

    teej107

    No it doesn't. What do you call this?
     
  20. Offline

    Coopah

  21. Offline

    teej107

    You can't use that method obviously. Do you not see the code that I'm quoting from you?
     
  22. Offline

    Areoace

  23. Offline

    teej107

    I wouldn't count on it. You are creating a new session and it's not the same one that you used when pasting.
     
  24. Offline

    Areoace

    Create new session -> Paste -> Unpaste, that's all he wants, the location ect will be in the new session. Infact @Coopah if you don't mind I'd like to see the solution :)
     
  25. Offline

    Coopah

    @teej107
    Still doesn't undo.
    Code:
    BukkitWorld BWf = new BukkitWorld(p.getWorld());
                                        EditSession es = new EditSession(BWf, 2000000);
                                        es.undo(es);
    You're telling me to create a new EditSession, that ain't going to work.
     
  26. Offline

    teej107

     
  27. Offline

    Areoace

    What @teej107 said is right and should very well be doable
     
  28. Offline

    Coopah

    @teej107
    I will say it again, when you want to acquire an edit session, it takes a player within the parameters.
     
  29. Offline

    teej107

    No it does not. Look at your code!!!!
    and because I'm beginning to question whether you read my suggestion or not, here is this!
    I've repeated my self too many times on this thread even before this post :p
     
    Areoace likes this.
  30. Offline

    Areoace

    @Coopah You have the edit session!

    Code:
                EditSession es =new EditSession(BWf, 2000000); 
    @teej107 beat me to it lmao

    One look into the WorldEdit javadocs and I find this


    EditSession(LocalWorld world, int maxBlocks)
    Construct the object with a maximum number of blocks.
    EditSession(LocalWorld world, int maxBlocks, BlockBag blockBag)
    Construct the object with a maximum number of blocks and a block bag.
     
    Last edited: Jan 11, 2016
Thread Status:
Not open for further replies.

Share This Page