Solved Resetting the map

Discussion in 'Bukkit Help' started by zachoooo, Jan 2, 2013.

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

    zachoooo

    Hey everyone,
    Does anyone know of a plugin that I can use to reset the map? My friends and I have built a relatively large map and every few days we want it set back to the way it was. Anyone know?
     
  2. Offline

    ifly6

    WorldEdit has a snapshot system, so you can restore it to previous versions. I am not completely sure what you're talking about, and I interpreted it as the above.
     
  3. Offline

    Perkun

    I think he just want to map delete and regenerate. If its true, just stop your server, delete map, and it'll be regenerated to basic form. XD
     
  4. Offline

    zachoooo

    No I don't want to regenerate it. I want it to go back to the way it was a while ago. Is worldedit automatic though? And how effective would it be at restoring massive areas without crashing?
     
  5. Offline

    Perkun

  6. Offline

    MyPictures

    If also looked for something like this @zachoooo

    I ended with using a plugin like My Worlds or multiverse and just copy the world again, again and again so I basically just merget the worlds and always switched to an other copy when I got done.

    I just used those 3 commands from My Worlds plugin:
    /world delete [worldname]
    /world copy [worldname] [newworldname]
    /tpp [worldname]
     
  7. Offline

    zachoooo

    I don't want it done manually. And I feel like rolling back an entire world could cause some serious errors.

    This sounds like a perfectly fine solution. Could I just write my own plugin to have these commands run every couple of days?
     
  8. Offline

    MyPictures

    Should work fine I guess. You may need a temp world while your actual one is deleting.

    I heard that its possible to restore worlds while they are loaded but I never saw a plugin that does this ;P (I don't even know if that possible but yea.)
     
    zachoooo likes this.
  9. Offline

    zachoooo

    Ok, I'll give it a shot
     
  10. Offline

    zachoooo

    My Worlds doesn't seem to be working? I wonder if multiverse can do this.

    Finally got it to work:

    Code:
    public static void reset() {
            executable = false;
            Map<String, Location> playerLocations = new HashMap<String, Location>();
            for (Player p : Bukkit.getOnlinePlayers()) {
                playerLocations.put(p.getName(), p.getLocation());
                p.teleport(Bukkit.getWorld("Spawn").getSpawnLocation());
            }
            Bukkit.broadcastMessage(ChatColor.GREEN + "The servers map is reloading. Please standby for the world reset. You will automatically be teleported back momentarilly.");
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mv delete world");
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mv confirm");
            File srcFolder = new File("./backup");
            File destFolder = new File("./world");
            if(!srcFolder.exists()){
                log.severe("Folder cannot be found. Shutting down.");
                Main.plugin.setEnabled(false);
            }else{
     
                try{
                    copyFolder(srcFolder,destFolder);
                }catch(IOException e){
                    e.printStackTrace();
                    //error, just exit
                    log.severe("Folder cannot be found. Shutting down.");
                    Main.plugin.setEnabled(false);
                }
            }
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mv import world NORMAL");
            Bukkit.broadcastMessage(ChatColor.GREEN + "The map has been reset. You will now be teleported back. Next reset is in one week.");
            for (Player p : Bukkit.getOnlinePlayers()) {
                if (playerLocations.containsKey(p.getName())) {
                    p.teleport(playerLocations.get(p.getName()));
                }
            }
        }
     
        public static void copyFolder(File src, File dest)
                throws IOException{
     
            if(src.isDirectory()){
     
                //if directory not exists, create it
                if(!dest.exists()){
                    dest.mkdir();
                }
     
                //list all the directory contents
                String files[] = src.list();
     
                for (String file : files) {
                    //construct the src and dest file structure
                    File srcFile = new File(src, file);
                    File destFile = new File(dest, file);
                    //recursive copy
                    copyFolder(srcFile,destFile);
                }
     
            }else{
                //if file, then copy it
                //Use bytes stream to support all file types
                InputStream in = new FileInputStream(src);
                OutputStream out = new FileOutputStream(dest);
     
                byte[] buffer = new byte[1024];
     
                int length;
                //copy the file content in bytes
                while ((length = in.read(buffer)) > 0){
                    out.write(buffer, 0, length);
                }
     
                in.close();
                out.close();
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page