Rebuild a world

Discussion in 'Spigot Plugin Development' started by to175, Jul 22, 2015.

  1. Hi, I need a code to rebuild a world. How to do please ?

    UPDATE : https://www.spigotmc.org/threads/rebuild-a-world.80045/#post-885540

    I need to :
    1 Tp all players to waiting room OK
    2 Unload the world Bukkit.unloadWorld
    3 Remove the world like that ?
    Code (Text):
    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                    @Override
                    public void run() {
                        new File(Bukkit.getWorldContainer(),WORLD).delete();
                    }}, 200);
    4 Create a new world + load like that ?
    Code (Text):
    public void loadWorld(String arena)
        {
                if(new File(getDataFolder(),NewWORLD).exists())
                {
                    File f = new File(Bukkit.getWorldContainer(),NewWORLD);
                    f.mkdirs();
                    FileUtil.copy(new File(getDataFolder(),NewWORLD), f);
                }
                Bukkit.createWorld(new WorldCreator(NewWORLD));
        }
    Is it correct ? Is "NewWORLD" my new world I have to use and "WORLD" the old one ?
     
    #1 to175, Jul 22, 2015
    Last edited: Jul 24, 2015
  2. Are you doing like a mini-game? You could disable saving then just restart the server.
     
    • Agree Agree x 1
  3. Thanks,
    I will not restart the server each time 2 players want to play 5 minutes while 30 others are playing an other game...
    Maybe can I "disable saving" then just unload/load the world ? So how to disable saving ? (I don't know how my server is saved :eek:)

    EDIT :
    no, I will not. I don't know plugins of others... I have my plugin on bukkit.org !

    I'm just asking for some help about the code I have ;)
     
  4. If I were you, I would not give set a new world for every new game that is coming. Especially when you have small minigames.
     
  5. Thanks,
    This is not a "small" mini game. This is the only game I have to rebuild !
    "set a new world" ?
    That is just to reload the map... I need to delete the old then to load a cleared save ...
     
  6. Oh ok, I wasn't sure of the context. I was just suggesting it. But I think that disabling then unloading/loading should work. I think its world.disableSaving() I dont even remember.
     
    • Like Like x 1
  7. Thanks,
    I can't disable saving :
    Is my code ok ? :p
     
  8. Well, you could try a more elegant approach. Log all player actions, then undo them at the end of the game.
     
    • Agree Agree x 1
  9. Thanks,
    I don't understand. omg, it is heavy, isn't it ??? They are supposed to break thousand of blocks.
    This is not a "minigame" this is something like a Hungergames were they need to break blocks.
    And I really don't know how to log blocks :')
    ps : I will not add a dependency.
     
  10. Remember: There are some things you simply can't log at all (lava or water for instance), and therefore wont get reset with any kind of block logging technique. The best approach is to fully reset the world.
     
  11. One can simply:
    1) Create the world, when the world is created call World#setAutoSave(false)
    2) At game end, unload the world without saving (Bukkit.unloadWorld(<world>, false))
    3) Then load it again using step 1
     
    • Like Like x 1
  12. And if they have a autoSave plugin ? No, I will not wright "please disable your autosave on the world..."
     
    • Creative Creative x 1
  13. I'm not sure if this is a feature in most autoSave plugins, but there might be an option to disable it in some worlds
     
  14. Maybe not, and I said I don't want that !

    I want to use my code... Please someone to help me with my code ?
     
  15. Please help me !
    Is those codes correct ? I think not :/

    • So first in onEnable I'm checking if worldName+"#tksave" exists. If false then I create it from worldName.
    Code (Java):
     if(new File(getDataFolder(), worldName+"#tksave").exists()){
                getLogger().info(worldName+"#tksave"+" exists.");
           }else{
               File worldNameLoading = new File(Bukkit.getWorldContainer(), worldName);
                worldNameLoading.mkdirs();//crée le dossier
                FileUtil.copy(new File(getDataFolder(), worldName+"#save"), worldNameLoading);
                Bukkit.createWorld(new WorldCreator(worldName));
                getLogger().info(worldName+"#tksave"+" created.");
           }
    • Reload the world, delete worldName then create worldName from worldName+"#tksave".
    Code (Java):
    public void reloadWorld(String map){
            getLogger().info("Reload "+worldName);
           try{
               for(Player p : Bukkit.getOnlinePlayers())
                   if(p.getLocation().getWorld().getName().equals(worldName))
                        p.teleport(Bukkit.getWorld(worldSpawn).getSpawnLocation());
                Bukkit.unloadWorld(worldName, false);//on unload map
                getLogger().info(worldName+" unload.");
                Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                    @Override
                   public void run() {
                       new File(Bukkit.getWorldContainer(), worldName).delete();//on delete map
                        getLogger().info(worldName+" deleted.");
                   }}, 200);
           }catch(Exception e){
           
           }
           if(new File(getDataFolder(), worldName+"#tksave").exists()){
               File worldNameLoading = new File(Bukkit.getWorldContainer(), worldName+"#tksave");
                worldNameLoading.mkdirs();//crée le dossier
                FileUtil.copy(new File(getDataFolder(), worldName), worldNameLoading);
           }
            Bukkit.createWorld(new WorldCreator(worldName));
            getLogger().info(worldName+" created.");
       }