A good way to create, unload, replace, load a world

Discussion in 'Plugin Development' started by nuno1212sss, Jan 19, 2015.

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

    nuno1212sss

    I'm creating a skywars plugin, with self forming arenas that create worlds when ever needed.
    This is what I use to create, unload, replace and load a world:
    Code:
    final World w =Bukkit.createWorld(new WorldCreator(worldname));
                        new BukkitRunnable(){public void run() {
                            if(Bukkit.unloadWorld(w,false))
                            WorldReplicator.move(worldmodule, w.getWorldFolder());
                        }}.runTaskAsynchronously(pl);
                        Bukkit.createWorld(new WorldCreator(worldname));
                        World we = Bukkit.getWorld(worldname);
                        ArenaInstance is = new ArenaInstance(u,we,pl,m);
                        waiting.add(is);
                        long t = System.currentTimeMillis()-time;
    WorldReplicator:
    Code:
    if (!ignore.contains(source.getName())) {
                if (source.isDirectory()) {
                    if (!target.exists())
                        target.mkdirs();
                    String files[] = source.list();
                    for (String file : files) {
                        File srcFile = new File(source, file);
                        File destFile = new File(target, file);
                        move(srcFile, destFile);
                    }
                } else {
                    InputStream in = new FileInputStream(source);
                    OutputStream out = new FileOutputStream(target);
                    byte[] buffer = new byte[1024];
                    int lenght;
                    while((lenght = in.read(buffer))>0)
                        out.write(buffer,0,lenght);
                    in.close();
                    out.close();
                }
            }
    This takes around 3.5 seconds(During that time the server breaks), and that is too much, any1 knows a way to create worlds async? as this is the only solution that I see.
    Thank you for reading!
     
  2. Offline

    1Rogue

    Pre-generate arenas and worlds, then copy them over from a separate file folder and load them.
     
  3. Offline

    nuno1212sss

    Update: Setting the worldtype to flat sets the load time to 435 ms(Didn't remember that :p)

    Already done :D

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Jan 19, 2015
Thread Status:
Not open for further replies.

Share This Page