Solved NullPointerException When Creating A World

Discussion in 'Spigot Plugin Development' started by Spedwards, Jun 16, 2016.

  1. I'm trying to generate a new world each time the server starts, however it's throwing a NPE on the line below.

    Code (Text):
    Bukkit.createWorld(new WorldCreator("world").generator(new DeathGamesGenerator()).generateStructures(true));
    I made a change to the plugin and now Bukkit#getWorld is throwing the NPE.

    Because a function in my plugin modifies terrain generation, I need to have the plugin loaded in before the worlds are, which is why this is happening.

    Can anyone help out? Essentially I just need to create a new world overwriting the old one every time the server starts up, using my custom terrain generation.
  2. new DeathGamesGenerator()
    is throwing NPE. Show class. Also ensure the world doesn't already exist
  3. Code (Text):
    public class DeathGamesGenerator extends ChunkGenerator {
        List<BlockPopulator> populators = new ArrayList<BlockPopulator>();
        public DeathGamesGenerator() {
            populators.add(new MushroomPopulator());
        public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {
            List<Biome> blacklist = Arrays.asList(Biome.BEACHES, Biome.COLD_BEACH, Biome.FROZEN_OCEAN, Biome.HELL, Biome.MUSHROOM_ISLAND, Biome.MUSHROOM_ISLAND_SHORE, Biome.OCEAN, Biome.SKY, Biome.STONE_BEACH, Biome.VOID);
            if (blacklist.contains(biome.getBiome(x, z))) {
                biome.setBiome(x, z, Biome.PLAINS);
            return super.generateChunkData(world, random, x, z, biome);
        public List<BlockPopulator> getDefaultPopulators(World world) {
            return populators;
  4. Best to actually show the NPE instead of just saying you have one.
  5. I didn't include it because it tells you absolutely nothing that I haven't already mentioned. Though if you really want it, here.

    Code (Text):

            at me.spedwards.deathgames.Main.onEnable( ~[?:?]
            at ~[spigot-1.9.4-R0.1-SNAPSHOT.jar:git-Spigot-8a048fe-106ced0]
            at [spigot-1.9.4-R0.1-SNAPSHOT.jar:git-Spigot-8a048fe-106ced0]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin( [spigot-1.9.4-R0.1-SNAPSHOT.jar:git-Spigot-8a048fe-106ced0]
            at org.bukkit.craftbukkit.v1_9_R2.CraftServer.loadPlugin( [spigot-1.9.4-R0.1-SNAPSHOT.jar:git-Spigot-8a048fe-106ced0]
            at org.bukkit.craftbukkit.v1_9_R2.CraftServer.enablePlugins( [spigot-1.9.4-R0.1-SNAPSHOT.jar:git-Spigot-8a048fe-106ced0]
            at net.minecraft.server.v1_9_R2.DedicatedServer.init( [spigot-1.9.4-R0.1-SNAPSHOT.jar:git-Spigot-8a048fe-106ced0]
            at [spigot-1.9.4-R0.1-SNAPSHOT.jar:git-Spigot-8a048fe-106ced0]
            at Source) [?:1.8.0_77]
  6. Paste coder from main Class line 45
  7. I did.