Solved Issue with WorldEdit API

Discussion in 'Plugin Development' started by Fl1pzta, Aug 19, 2013.

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

    Fl1pzta

    While using the WorldEdit API I'm having an issue with torches,buttons,levers,doors(blocks that depend on another block) being pasted. They will just drop off and not paste correctly. If anyone knows a fix for this it'd be much appreciated.

    Here's my code right now for pasting the schematic.
    Code:java
    1. @SuppressWarnings("unused")
    2. private void loadArea(Queue queue)
    3. throws DataException, IOException, MaxChangedBlocksException
    4. {
    5. String name=queue.getBName(),pname=queue.getPName();
    6. SubRegion thisRegion = queue.getRegion();
    7. Location loc=queue.getLoc();
    8. BlockFace direction=queue.getDirection();
    9. Player player = Bukkit.getPlayer(pname);
    10. if(!player.isOnline()){
    11. return;
    12. }
    13. File file = new File(Util.mainDir()+"/Buildings/"+name+".schematic");
    14. EditSession es = new EditSession(new BukkitWorld(Util.getWorld()), Integer.MAX_VALUE);
    15. CuboidClipboard cc = SchematicFormat.MCEDIT.load(file);
    16.  
    17. Vector origin = BukkitUtil.toVector(loc);
    18. //cc.setOrigin(origin);
    19. int height = cc.getHeight();
    20. double x1,x2=0,y1,y2,z1,z2=0;
    21. y1 = loc.getY();
    22. y2 = loc.getY()+height;
    23. x1 = loc.getX();
    24. z1 = loc.getZ();
    25. if(direction ==BlockFace.NORTH){
    26. x2 = x1-cc.getWidth();
    27. z2 = z1+cc.getLength();
    28. }
    29. if(direction ==BlockFace.SOUTH){
    30. cc.rotate2D(180);
    31. x2 = x1+cc.getWidth();
    32. z2 = z1-cc.getLength();
    33. }
    34. if(direction ==BlockFace.EAST){
    35. cc.rotate2D(90);
    36. x2=x1-cc.getWidth();
    37. z2=z1-cc.getLength();
    38. }
    39. if(direction==BlockFace.WEST){
    40. cc.rotate2D(270);
    41. x2=x1+cc.getWidth();
    42. z2=z1+cc.getLength();
    43. }
    44. cc.paste(es, origin,false);
    45. player.sendMessage(ChatColor.GREEN + "Your " + name + " building has been placed.");
    46. int minx = (int)Math.floor(Math.min(x1, x2));
    47. int maxx =(int) Math.ceil(Math.max(x1, x2));
    48. int minz = (int)Math.floor(Math.min(z1, z2));
    49. int maxz = (int)Math.ceil(Math.max(z1, z2));
    50. player.sendMessage("minx: " + minx + " maxx: " + maxx + " minz " + minz + " maxz: " + maxz);
    51. int newmax = thisRegion.getMaxBuilding(name)+1;
    52. String newname = name + "" + newmax;
    53. String type = BuildingConvert.convert(name);
    54. new GenerateBuilding(thisRegion, newname, type,new Location(Util.getWorld(),minx,21,minz),
    55. new Location(Util.getWorld(),maxx,y2,maxz));
    56. }


    Also, I'm interested about slowly pasting the schematic, but I've thought about a couple issues I'm not sure how to get around...
    • What if the server crashes mid-paste.
    • Keeping track of blocks that have yet to be pasted in case of a cancel mid-paste
    • Pasting blocks that depend on adjacent blocks last
    Thank you in advance.
     
  2. Offline

    Fluxty

    pls yes
     
  3. Offline

    Fl1pzta

    Anyone curious on how to do this in the future. Before pasting your schematic, EditSession has a method called enableQueue() and that makes so those blocks are pasted last. Just make sure you disable the Queue with disableQueue() or it won't paste at all.

    As for the second question, I've found a plugin called SafeEdit and I requested an API for it.
    LINK TO SAFEEDIT--> http://dev.bukkit.org/bukkit-plugins/safeedit/
     
Thread Status:
Not open for further replies.

Share This Page