Config file problems

Discussion in 'Plugin Development' started by Fedmand, Dec 29, 2013.

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


    Hello there,

    I have some problems with a config variable not loading :(
    This is where i load it:
    World world1 = Bukkit.getWorld(getConfig().getString("worlds.hub"));
    (which is also the place where the console error sends me for a "nullPointer")

    This is what my config.yml looks like:
      hub: build
      arenas: Jetpack
    The config file is created inside onEnable:
    The config file is created like i want it to with the Defaults there and everything.

    Everything seems perfect to me :(
    But apparently it isn't. I get a nullPointer at:
    World world1 = Bukkit.getWorld(getConfig().getString("worlds.hub"));
    like i said before. Do you guys know what I'm doing wrong?
    Thank you so much!
  2. Offline


    Did you create "worlds:" in the config as a section? If so, you need to use
    If that's not the case, then I'm not sure what's wrong with it.
  3. Offline


    Fedmand Are you doing the World world1 = Bukkit.getWorld() inside of your onEnable(); ? You can't assign a world to a variable if Bukkit itself isn't enabled yet (which means doing Bukkit.getWorld() won't return a world, but isntead null)
  4. Offline


    I put the "World world1 = Bukkit.getWorld()" below onEnable. Is that okay or does it have to be inside? I've already tried inside and that didn't work out either :(

    I am doing it like:

    worlds: hub: {worldName}
    arenas: {worldName}
  5. Offline


    Fedmand You have to initialize it inside of onEnable(), you can't exactly get a world before Bukkit has gotten the world into it, can you?
  6. Offline


    I've initialized them inside onEnable() now and I'll quickly find the result

    Okay. The plugin obviously loaded this time. The nullPointer now happens when i try to use the variables.
    This is what i have above onEnable():
    World world1;
    World world;
    Location lobby;
    Location spectate;
    Location spawn1;
    Location spawn2;
    Location spawn3;
    Location spawn4;
    Location spawn5;
    Location spawn6;
    Location spawn7;
    Location spawn8;
    Location spawn9;
    Location spawn10;
    And inside onEnable():
    world1 = Bukkit.getWorld(getConfig().getString("worlds.hub"));
    world = Bukkit.getWorld(getConfig().getString("worlds.arenas"));
    lobby = new Location(world, getConfig().getDouble("lobby..x"),
    getConfig().getDouble("lobby.y"), getConfig().getDouble(
    spectate = new Location(world,
    getConfig().getDouble("16:1.spectate.x"), getConfig()
    .getDouble("16:1.spectate.y"), getConfig().getDouble(
    spawn1 = new Location(world, getConfig().getDouble("16:1.spawn1.x"),
    getConfig().getDouble("16:1.spawn1.y"), getConfig().getDouble(
    spawn2 = new Location(world, getConfig().getDouble("16:1.spawn2.x"),
    getConfig().getDouble("16:1.spawn2.y"), getConfig().getDouble(
    spawn3 = new Location(world, getConfig().getDouble("16:1.spawn3.x"),
    getConfig().getDouble("16:1.spawn3.y"), getConfig().getDouble(
    spawn4 = new Location(world, getConfig().getDouble("16:1.spawn4.x"),
    getConfig().getDouble("16:1.spawn4.y"), getConfig().getDouble(
    spawn5 = new Location(world, getConfig().getDouble("16:1.spawn5.x"),
    getConfig().getDouble("16:1.spawn5.y"), getConfig().getDouble(
    spawn6 = new Location(world, getConfig().getDouble("16:1.spawn6.x"),
    getConfig().getDouble("16:1.spawn6.y"), getConfig().getDouble(
    spawn7 = new Location(world, getConfig().getDouble("16:1.spawn7.x"),
    getConfig().getDouble("16:1.spawn7.y"), getConfig().getDouble(
    spawn8 = new Location(world, getConfig().getDouble("16:1.spawn8.x"),
    getConfig().getDouble("16:1.spawn8.y"), getConfig().getDouble(
    spawn9 = new Location(world, getConfig().getDouble("16:1.spawn9.x"),
    getConfig().getDouble("16:1.spawn9.y"), getConfig().getDouble(
    spawn10 = new Location(world, getConfig().getDouble("16:1.spawn10.x"),
    getConfig().getDouble("16:1.spawn10.y"), getConfig().getDouble(
    This error happens when i try to use the world1 variable:

    Line 322:
    I guess we're back at the beginning :(
  7. Offline


    Fedmand My guess is that you are trying to get a world that doesn't actually exist, make sure that the world itself actually exists
  8. Offline


    Anyone know the sulotion?
Thread Status:
Not open for further replies.

Share This Page