1.8.8 import a schematic using world edit api

Discussion in 'Spigot Plugin Development' started by sir_dynamo, Mar 11, 2020.

  1. Hello I am coding a speed uhc plugin, and I'd like to use a nether biome populator that pastes a nether.schematic file that contains my nether. I know this is a recuring question about the world Edit api but so far I've gone through every single forum and none of the solutions have worked from me (I always get a bunch of deprecated methods etc...). The thing is I just got into the world Edit API and I don't know how to use it at all and I don't really intend to since it's such a small portion of my plugin. here's the code of my nether populator, the loadSchematic method being the one I'd like to create
    Code (Java):
    package fr.dynamo.uhcrun.world.populator;

    import java.util.Random;
    import org.bukkit.Bukkit;
    import org.bukkit.Chunk;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.generator.BlockPopulator;

    import fr.dynamo.uhcrun.UHCRun;

    public class NetherPopulator extends BlockPopulator {
        public String filename = "nether.schematic";
        public UHCRun pl;
        public NetherPopulator(UHCRun instance) {
            this.pl = instance;

        public void populate(World world, Random random, Chunk chunk) {
            for(int x = 0; x < 16; x++) {
                for(int y = 0; y < 16; y++) {
                    for(int z = 0; z < 20; z++) {
                        if(Math.random()<0.00001) {
                            Location loc = new Location(Bukkit.getWorld("world"),x,y,z);
                            this.loadSchematic(loc, filename);
        private void loadSchematic(Location loc, String file) {
            //please send help
  2. just to make sure i am correct, you want to use an custom world generator with an custom chunk, and in your case you want to set in the chunk each block to an different type? Basically that's what you are currently trying right?

    First of all, correct your usage issue basically this:

    Location loc = new Location(Bukkit.getWorld("world"),x,y,z); world always be for every chunk the same location, cause you don't use the chunk coordinate, you just use the loop coordinate for each block. which would be always like 0,0,0 or 1,1,1, ...
    make sure to use as x the chunk min and the < as chunk max ect.

    Then you are trying to perform an method for each block. Basically that's ok if each block should be different, but it sounds weeird, or do you just want like buildings in your world?
    if so then its an huge different usage than you are doing it rn.
  3. No the code is checking for each block below Y=20 within a chunk. For each one of those blocks it generates a random double between 0 and 1. If this number < 0.00001 , it generates the nether biome at this location.
    I know my schematics can overlap and all but that's not the issue I'm dealing with rnYou're def right about the location that's my bad I'll fix that
  4. SteelPhoenix


  5. not sure if you don't know it, or whatever but 20 is only your z pose not y..
    "For each one of those blocks it generates a random double between 0 and 1" Your Math.random() will generate an very long number between 0.0 and 1.0 the fact that the number will be someday lower than 0.00001 is just wow, maybe 1 time in the world then..
    If you just want to have an nether biome at the location then just change it manually using the spigot api..
  6. indeed that's another mistake I just fixed it.
    0,00001 isn't that low when you consider the check is made 5000+ times per chunk. For now you have 1/100000 chance per block of the nether being generated. The map is 1000 *1000 blocks
  7. SteelPhoenix


    Keep in mind he checks this >5k times per chunk population, it is still pretty likely to occur.

    Also OP, the location you are using is not relative to the chunk and world you are populating.

    Edit: snipd
  8. I 'll fix that with Location loc = chunk.getBlock(X, y, z).getLocation()
  9. DavidDevelops


  10. You
    Indeed gave me a parser I decided to use mcedit after all. I created another thread because the problem isn't the same anymore
  11. DavidDevelops


    I really don't undestand what you're saying the issue is than, I assume you mean worldedit not mcedit but still, I don't see what you're asking for help with then? Also your thread title says "using spigot api" I'd suggest changing it to "using worldedit API"
    If you DID find solutions to the problem you have they are deprecated, You can just go to the API and find the new methods instead of using the deped ones,
  12. Yes sorry I changed the title that's my bad,
    My issue hasn't changed I'm still trying to import a schematic into a world but I thought I 'd use the world edit API after all
  13. DavidDevelops


    To avoid further creating hassle I believe this is what you're looking for?
    You can also look into the WorldEdit API References to find more information on any given method or class used/mentioned.
  14. I found something interessting here: however I have a few issues:
    Code (Text):
    public boolean loadAndPaste(String schematic, WorldEdit we, LocalSession session, WorldData worldData, EditSession editSession, Vector location) throws FilenameException {

            String filename = schematic + ".schematic";
            LocalConfiguration config = we.getConfiguration();

            File dir = we.getWorkingDirectoryFile(config.saveDir);
            // File f = we.getSafeOpenFile(player, dir, filename, "schematic", "schematic");
            File f = new File(dir, filename);

            if (!f.exists()) {
                System.out.println("Schematic " + filename + " does not exist!");
                return false;

            ClipboardFormat fileFormat = ClipboardFormat.findByFile(f);
            ClipboardFormat aliasFormat = ClipboardFormat.findByAlias("mcedit");
            ClipboardFormat format = (fileFormat == null) ? aliasFormat : fileFormat;
            if (format == null) {
                System.out.println("Unknown schematic format for file " + f.getName());
                return false;

            Closer closer = Closer.create();
            try {
                String filePath = f.getCanonicalPath();
                String dirPath = dir.getCanonicalPath();

                if (!filePath.substring(0, dirPath.length()).equals(dirPath)) {
                    System.out.println("Clipboard file could not read or it does not exist.");
                } else {
                    FileInputStream fis = closer.register(new FileInputStream(f));
                    BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
                    ClipboardReader reader = format.getReader(bis);
                    Clipboard clipboard = reader.read(worldData);
                    session.setClipboard(new ClipboardHolder(clipboard, worldData));
    How do I get the LocalSession, worldData and, EditSession, without a player?
  15. Haven't found a solution yet for pasting if anybody could hep
  16. My main issue is that it is nearly impossible to find the javadoc for World Edit 6, so even though I do find code that might be useful, if there is a slight difference with what I'd like to get it messes everything up because I don't know what a lot of the objects and methods do.
  17. DavidDevelops


    Well... That's what the docs are kind of for? is for you to learn what they all do? So, if you are trying to PASTE a schematic using worldedit API it's extremely easy literally just google for a tutorial on worldedit API if you don't want to dig into the docs yourself. I provide help not spoonfed code, Please take some time to learn what you're trying to do.
  18. I've gone through most of the tutorials, but as I said earlier the method used are deprecated and I can't find the javadpc anywhere, and apparently I'm not the only one. If you don't wanna provide code that's find I don't really care, for now I'm looking for the hava doc. I've found links from people who generated it but they were dead
    #18 sir_dynamo, Mar 14, 2020
    Last edited: Mar 14, 2020
  19. You can build the Javadoc/import it in your IDE by yourself.
  20. Hello, I stopped working on my project for a while, but I think I'll be back at it pretty soon. I know how to generate the javadoc for a project but how do I generate the javadoc of world edit since it's just a referenced librairy (I imported an external jar and added to the librairies)