Bukkit.getWorld(String name) returns null

Discussion in 'Plugin Development' started by arinerron, May 15, 2015.

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

    arinerron

    I have a Minigame plugin and in it, there is a NullPointerException...
    Code:
    int x = this.getConfig().getInt("Minigame.MiniG.lobby.x");
    int y = this.getConfig().getInt("Minigame.MiniG.lobby.y");
    int z = this.getConfig().getInt("Minigame.MiniG.lobby.z");
    World world = Bukkit.getWorld(this.getConfig().getString("Minigame.MiniG.lobby.world"));
    this.MINIGAMES.get(i).setLobby(new Location(world, x, y, z));
    
    Just so you know, I checked and confirmed the world name is "tester"!
    The config file ==
    Code:
    # Data for Minigame plugin is located here.
    Minigames:
    - test
    Minigame:
      MiniG:
        title: test
        minplayers: 3
        maxplayers: 3
        lobby:
          x: 1
          y: 1
          z: 1
          world: tester
        twospawn:
          x: 1
          y: 1
          z: 1
          world: tester
        threespawn:
          x: 1
          y: 1
          z: 1
          world: tester
    
     
    Last edited: May 16, 2015
  2. Offline

    Freelix2000

    There is no "MiniG" key under Minigames. You have to set a value before you can get it... This is the value you're trying to get:


    Code:
    Minigames:
      MiniG:
        lobby:
          world: world_name
     
  3. Offline

    arinerron

    @Freelix2000
    Sorry I accidently did that... I fixed it... I pasted my old version of the config file...
     
  4. Offline

    mine-care

  5. Offline

    arinerron

    But it's not solved... I mean I showed the simplified version of the error here... I just had a typo but in the real program, it is still doing the same thing (returning null...)
     
  6. Online

    timtower Administrator Administrator Moderator

    @arinerron Is that world loaded then when that code is running?
     
  7. Offline

    arinerron

    WOAH I NEVER THOUGHT OF THAT... I will check, thanks alot! :) Just curious, if it is not, how will I get past this problem? Is there an event for when the server finishes starting up?
     
  8. Online

    timtower Administrator Administrator Moderator

    You check if the world is loaded in the onEnable ( generally it is )
    Or you listen to the WorldLoadEvent, or something along those lines.
     
  9. Offline

    mine-care

    @arinerron Oh sorry i thought you ment the thread when you said "i fixed it" :3
     
  10. Offline

    arinerron

    Oh! :) Sorry about the confusion, I will attempt to do better next time! :)

    The first time I start the server, it says it's an invalid plugin cause a NullPointerException, (And it loads before the world is loaded), but the second time I reload it doesn't say the world was reloaded so I don't know if it is, but I get an error (The first time I reload it following the plugin stopping, the plugin works...)

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: May 16, 2015
    mine-care likes this.
  11. Online

    timtower Administrator Administrator Moderator

    @arinerron That sentence doesn't really make sense to me, could you try to say it with different words?
     
  12. Offline

    Tecno_Wizard

    @arinerron, you're trying to get the world before it exists is what it sounds like.
     
  13. Offline

    arinerron

    Okay thanks! I'll make it display all the worlds before it try's to run the function Bukkit.getWorld(). I'll try it when I get home!
     
Thread Status:
Not open for further replies.

Share This Page