How do i copy a world

Discussion in 'Spigot Plugin Development' started by Kars_YiFeng, Jul 14, 2019 at 11:59 AM.

  1. How to copy a world.
    Any solution will do
    I prefer to copy a world without having to copy world files.
     
  2. You cant copy a world without world files xd
    I recommend using nio Files
     
  3. I don't know what is nio Files.
    I m going to create a temporary world. As a instance zone. This world will be deleted before shutting down the server. How can I do this?
    But its hard to copy whole world. Can I just copy an area from Location A to B?
     
  4. No, it would be probably harder. There is a simple way to fo this:
    Code (Text):
    void createNewWorld(World world){
         File worldDir = world.getWorldFolder();
         String newName = world.getName() + "_temp";
         FileUtils.copyDirectory(worldDir, new File(worldDir.getParent(), newName));

         WorldCreator creator = newWorldCrator(newName);
         World newWorld = Bukkit.createWorld(creator);
    }
     
  5. Your best solution is copying the directory. If you want to quickly copy location A to B I suggest using WorldEdit ( or FastAsyncWorldEdit in case it is updated... ) and make a schematic out of it.
     
  6. Thank you :D.
    Is this World Creator read the world folder while creating a new world?
     
  7. Thanks. But I prefer to copy the world folder because I didn't find the javadocs of WorldEdit :p
     
  8. Yes!

    Btw, are you creating a temporary world for minigames? If so, I'd suggest you to use schematics if the arena to be reset is not that large (because there is no need to create a world for each small arena), otherwise you probably have to use the above approach to reset the whole world.
     
  9. Not minigames.
    I'm developing a role play games plugin. I am developing the InstanceZone section. My design idea is as follows: 1. The administrator selects an area as the game area of InstanceZone.2. When a player wants to enter this InstanceZone, the server creates a new temporary world for the player and copies the area to be entered. This prevents multiple players from fighting each other in the same InstanceZone, and can also create stories.[From Machine Translation...]

    I don't know how to use schematics. Can you give me some suggestions or examples?