Help with WorldEdit API

Discussion in 'Spigot Plugin Development' started by Bolt, May 4, 2015.

  1. I'm trying to use WorldEdit as a dependency to load schematics in my plugin. I have 2 questions :

    1. I noticed that the CuboidClipboard class itself is deprecated. If so, I would like to know if an alternative was created for the class.

    2. I've read the schematic into a CuboidClipboard but I want to implement my own pasting method. How would I go about the pasting of blocks since CuboidClipboard contains BaseBlock and not Block. I know I can just do getID() from BaseBlock and do setID() for Block, but I want to be able to know how I can set the NbtData which is stored in BaseBlock or else the NbtData such as sign text and chest contents will be lost
     
    #1 Bolt, May 4, 2015
    Last edited: May 4, 2015
  2. Would it be possible to cast a CompoundTag (NbtData) to a MetadataValue?
     
  3. NathanWolf

    Supporter

    You can use BaseBlock.getNBTData to get a block's NBT data (as a WE CompoundTag object), and you can also use the various sub-classes of BaseBlock to handle translating that data for you (such as creating a SignBlock and calling setNBTData).

    I'm not certain that a CuboidClipboard already contains the sub-classes for appropriate block types... that'd make sense, but as I look back at my old code for loading WE schematics, it seems like I assume this is not true.

    If you'd like some example code, here is how I used to do this:

    https://github.com/elBukkit/MagicPl...ers/mine/bukkit/block/WorldEditSchematic.java
     
    • Informative Informative x 1
  4. @NathanWolf Thanks! I'm a bit confused though. In your code, you used a type called MaterialAndData. Where did you get it because I don't think it's a native spigot class.
     
    #5 Bolt, May 5, 2015
    Last edited: May 5, 2015
  5. NathanWolf

    Supporter

    It is not, that's my own internal class for representing a block/item type. You'll have to take that code as a basic example- I wouldn't necessarily do it the way I was doing it, but that should at least point you in the direction of the right WE API methods to use :)
     
  6. @NathanWolf Oh ok. I think I got my code working now. Thanks so much! :)
     
    • Like Like x 1