World rebuild

Discussion in 'Plugin Development' started by To175, Jul 24, 2015.

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

    To175

    Hi, I need to rebuild a world myself.
    I saw topics but not answered ...

    I have modified codes. I want to know : is my code correct ?! Help me please :)

    The plugin must :
    =>
    • So first in onEnable I'm checking if worldName+"#tksave" exists. If false then I create it from worldName.
    Code:
           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:
           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.");
        }
    Like that I have a clean worldName.

     
    Last edited: Jul 24, 2015
  2. Offline

    Eos

    Error?
     
  3. Offline

    Hawktasard

    @To175
    To "roll back" a world, you can unload it with
    Code:java
    1. Bukkit.unloadWorld(name, false);
    and then load it back normally.
    This will work as long as you have save-all off for this world and nobody saves the world manually
     
  4. Offline

    To175

    There is not any error, read my question.
    I meant, I want to know if my code is correct ?

    @Hawktasard
    Thanks, I'm not asking "is there an other way", I'm asking if my code is correct.
     
  5. Offline

    Eos

    Check if it works, if not then it doesn't work.
     
  6. Offline

    To175

    @Eos thanks, go away now.
     
Thread Status:
Not open for further replies.

Share This Page