Reloading a world from a folder

Discussion in 'Plugin Development' started by iTristan, Jan 27, 2013.

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


    I am currently writing a plugin ot automate matches of the "The Walls CTF Edition" map.

    While I have most of the gameplay code done, I realised that I overlooked a big problem which is reloading the map every game. I currently run a server the "The Walls" maps and the plugin I use (and contribute to) uses a special script that copies a backup of the untouched map back to the world folder after stopping the server before restarting it.

    I am wondering if there is a way to delete the current (and only) world after the game ends and reload a fresh copy from a folder. (E.g. all players are kicked, world is deleted, world is reloaded, server is restarted with wrapper such as MCMA or Rtoolkit).


    I have done a bit of work now and have come up with this :

    public class ReloadMap {
        public static void reloadMap() {
            //Kick players
            for (Player pl : Bukkit.getOnlinePlayers()){
                pl.kickPlayer(ChatColor.GREEN + "The server is restarting!");
            //Prevent them from joining
            Bukkit.getServer().unloadWorld(TheWallsCTF.wallsWorld, true);
            try {
                FileUtilities.emptyFolder(new File(TheWallsCTF.wallsWorld));
                (new File(TheWallsCTF.wallsWorld)).delete();
                FileUtilities.copyFolder(new File("WallsCTF"), new File(TheWallsCTF.wallsWorld));
            catch (Exception e) {
            //Re allow joining
            //Restart the server
    I'm not exactly sure if it's the right way to do it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page