Trying to Load/Delete World, Console Error

Discussion in 'Plugin Development' started by Muod, May 1, 2014.

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

    Muod

    In my main server directory, I have a world folder called "Game". To load the world I use :
    Code:java
    1. public static void loadMap(){
    2. WorldCreator wc = new WorldCreator("Game");
    3. World w = Bukkit.createWorld(wc);
    4. }

    Then to delete the world right after I use :
    Code:java
    1. public static boolean deleteDirectory(File path) {
    2. if( path.exists() ) {
    3. File files[] = path.listFiles();
    4. for(int i=0; i<files.length; i++) {
    5. if(files[i].isDirectory()) {
    6. deleteDirectory(files[i]);
    7. }
    8. else {
    9. files[i].delete();
    10. } //end else
    11. }
    12. }
    13. return( path.delete() );
    14. }
    15.  
    16. public static void resetMap(){
    17. for(Chunk c : Bukkit.getWorld("Game").getLoadedChunks()) {
    18.  
    19. c.unload(false, false);
    20.  
    21. }
    22. if (Bukkit.unloadWorld("Game", true)) {
    23. System.out.println("Unloaded world");
    24. } else {
    25. System.err.println("Couldn't unload world");
    26. }
    27. World worldtodelete = Bukkit.getWorld("Game");
    28. File folder = worldtodelete.getWorldFolder();
    29. deleteDirectory(folder); //delete world
    30. }[/i][/i][/i]


    In the console I get an error when doing a command that sets off loadMap then resetMap; The error is:
    Code:
    [21:51:05] [Server thread/INFO]: Unloaded world
    [21:51:05] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'resetmaptest' in plugin GemWars v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:703) ~[craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerConnection.java:955) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:817) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
    Caused by: java.lang.NullPointerException
        at com.minehit.Game.resetMap(Game.java:108) ~[?:?]
        at com.minehit.ResetMapTestCommand.onCommand(ResetMapTestCommand.java:19) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.7.9-R0.1-20140418.182938-15.jar:git-Bukkit-1.7.2-R0.3-56-g3779cff-b3072jnks]
        ... 13 more
    [22:05:19] [Server thread/INFO]: CONSOLE: Stopping the server..
    Line 108 is: World worldtodelete = Bukkit.getWorld("Game");
     
  2. Offline

    hintss

    I'd guess that your problem is that the world is null since you just unloaded it, so you can't Bukkit.getWorld() it.
     
Thread Status:
Not open for further replies.

Share This Page