Bukkit.getWorld(String) returns null.

Discussion in 'Plugin Development' started by Wehttam664, Oct 19, 2014.

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

    Wehttam664

    I'm trying to get a world for the getDefaultWorldGenerator() method, but the API continues to return null. Upon further inspection, the getWorlds() method returns an empty list. Why is this...?

    Code:java
    1. // Generator method
    2. public ChunkGenerator getDefaultWorldGenerator(String worldName, String id){
    3. getLogger().info("Applying TerraDirt generator to world `"+worldName+"`.");
    4. World world = Bukkit.getWorld(worldName); // Returns null, causes crash.
    5. ChunkGenerator gen = world.getGenerator();
    6. gen.getDefaultPopulators(world).add(new TerraOrePopulator());
    7. return gen;
    8. }


    Bukkit.getWorld(), Bukkit.getServer().getWorld(), and the plugin.getServer().getWorld() all fail; `worldName` has been debugged and proven to be correct, ruling it out. I've also ensured to have set `load:startup` and correctly configure the bukkit.yml. What's the issue here?

    Stack Trace for the map init:
    Code:
    [15:45:28] [Server thread/INFO]: Preparing level "map_1"
    [15:45:28] [Server thread/INFO]: [TerraDirt] Applying TerraDirt generator to world `map_1`.
    [15:45:28] [Server thread/ERROR]: [TerraDirt] Could not set generator for default world 'map_1': Plugin 'TerraDirt v01.01.03
    java.lang.NullPointerException
        at me.capit.TerraDirt.TerraDirt.getDefaultWorldGenerator(TerraDirt.java:37) ~[?:?]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.getGenerator(CraftServer.java:1335) [CORESERVER.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:220) [CORESERVER.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:210) [CORESERVER.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:458) [CORESERVER.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [CORESERVER.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
     
  2. Offline

    TheCodingCat

    what is on line 37
     
  3. Offline

    Gamecube762

    If a world is null, it probably isn't loaded.
     
  4. Offline

    Wehttam664

    Line 37 is the `world.getGenerator()` line. The variable `world` is null and thus causes an NPE.
     
  5. Offline

    RainoBoy97

    You have to load the world first.
     
Thread Status:
Not open for further replies.

Share This Page