Map Restoring

Discussion in 'Plugin Development' started by GamerzKing, Nov 24, 2015.

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

    GamerzKing

    Hello everyone!

    Currently I am making a mini-game, and after the game is over, I would like to reset the map. However, in the process of this, while unloading the world, I am getting some errors.


    Code:
    package com.GamerzKing.elementals.arena;
    
    import java.io.File;
    import java.io.IOException;
    
    import org.apache.commons.io.FileUtils;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.World;
    import org.bukkit.WorldCreator;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    
    public class ArenaManager {
    
        public static void restoreMap(final String worldName, long delay, Plugin plugin) {
    
            final File sourceFolder = new File(plugin.getDataFolder().getPath() + File.separator + worldName);
            final File worldFolder = new File(worldName);
            final World world = Bukkit.getWorld(worldName);
    
            if (world != null) {
                for (Player players : world.getPlayers()) {
                    if (players.isDead()) {
    
                        players.kickPlayer(ChatColor.RED + "You died!");
                    }
                }
    
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    
                    @Override
                    public void run() {
    
                        if (world == null || Bukkit.unloadWorld(world, true)) {
                            try {
    
                                FileUtils.copyDirectory(sourceFolder, worldFolder);
                                FileUtils.deleteDirectory(worldFolder);
    
                                if (Bukkit.createWorld(new WorldCreator(worldName)) == null) {
                                    System.out.println("An error occurred while loading the world " + worldName);
    
                                } else {
    
                                    System.out.println("The world " + worldName + " has been restored successfully.");
                                }
    
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
    
                        } else {
    
                            System.out.println("An error occurred while unloading the world " + worldName);
                        }
                    }
                }, delay);
            }
        }
    }
    Code:
                ArenaManager.restoreMap("Lobby", 200, Main.getPlugin());

    Code:
    24.11 18:13:49 [Server] INFO An error occurred while unloading the world Lobby
    24.11 18:13:50 [Server] INFO An error occurred while unloading the world Lobby
    24.11 18:13:50 [Server] INFO An error occurred while unloading the world Lobby
    24.11 18:13:51 [Server] INFO An error occurred while unloading the world Lobby
    24.11 18:13:52 [Server] INFO An error occurred while unloading the world Lobby
    If anyone can help solve this issue, that would be greatly appreciated! :)
     
  2. Offline

    CraftCreeper6

    @GamerzKing
    The world is null, you have two a null check there that tell you that.

    Have you typed it in correctly?
    Try using Bukkit#getWorld("world_name"); ?
     
Thread Status:
Not open for further replies.

Share This Page