Config file problems

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

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

    Fedmand

    Hello there,

    I have some problems with a config variable not loading :(
    This is where i load it:
    Code:
    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:
    Code:
    worlds:
      hub: build
      arenas: Jetpack
    
    The config file is created inside onEnable:
    Code:
    getConfig().options().copyDefaults(true);
            saveConfig();
    
    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:
    Code:
    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

    Freelix2000

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

    xTigerRebornx

    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

    Fedmand

    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

    xTigerRebornx

    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

    Fedmand

    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():
    Code:
    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():
    Code:
    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(
    "lobby.z"));
    spectate = new Location(world,
    getConfig().getDouble("16:1.spectate.x"), getConfig()
    .getDouble("16:1.spectate.y"), getConfig().getDouble(
    "16:1.spectate.z"));
    spawn1 = new Location(world, getConfig().getDouble("16:1.spawn1.x"),
    getConfig().getDouble("16:1.spawn1.y"), getConfig().getDouble(
    "16:1.spawn1.z"));
    spawn2 = new Location(world, getConfig().getDouble("16:1.spawn2.x"),
    getConfig().getDouble("16:1.spawn2.y"), getConfig().getDouble(
    "16:1.spawn2.z"));
    spawn3 = new Location(world, getConfig().getDouble("16:1.spawn3.x"),
    getConfig().getDouble("16:1.spawn3.y"), getConfig().getDouble(
    "16:1.spawn3.z"));
    spawn4 = new Location(world, getConfig().getDouble("16:1.spawn4.x"),
    getConfig().getDouble("16:1.spawn4.y"), getConfig().getDouble(
    "16:1.spawn4.z"));
    spawn5 = new Location(world, getConfig().getDouble("16:1.spawn5.x"),
    getConfig().getDouble("16:1.spawn5.y"), getConfig().getDouble(
    "16:1.spawn5.z"));
    spawn6 = new Location(world, getConfig().getDouble("16:1.spawn6.x"),
    getConfig().getDouble("16:1.spawn6.y"), getConfig().getDouble(
    "16:1.spawn6.z"));
    spawn7 = new Location(world, getConfig().getDouble("16:1.spawn7.x"),
    getConfig().getDouble("16:1.spawn7.y"), getConfig().getDouble(
    "16:1.spawn7.z"));
    spawn8 = new Location(world, getConfig().getDouble("16:1.spawn8.x"),
    getConfig().getDouble("16:1.spawn8.y"), getConfig().getDouble(
    "16:1.spawn8.z"));
    spawn9 = new Location(world, getConfig().getDouble("16:1.spawn9.x"),
    getConfig().getDouble("16:1.spawn9.y"), getConfig().getDouble(
    "16:1.spawn9.z"));
    spawn10 = new Location(world, getConfig().getDouble("16:1.spawn10.x"),
    getConfig().getDouble("16:1.spawn10.y"), getConfig().getDouble(
    "16:1.spawn10.z"));
    
    This error happens when i try to use the world1 variable:
    http://pastebin.com/FWaPPBKw

    Line 322:
    Code:
    player.teleport(world1.getSpawnLocation());
    
    I guess we're back at the beginning :(
     
  7. Offline

    xTigerRebornx

    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

    Fedmand

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

Share This Page