Bukkit.getWorld(worldName) returns null

Discussion in 'Plugin Development' started by Richard12799, Jan 16, 2017.

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

    Richard12799

    Hello everyone!

    I have a String containing the name of a world that I know exists because I can teleport to the World via Multiverse. However, when I try to access the World via Bukkit.getWorld(worldName) in my plugin's onEnable method, it returns null(I printed worldName to the console and the name is correct). I listed Bukkit.getWorlds() and my world isn't there. Is there a way to force the world to load?

    Thanks!
    Rich
     
  2. Offline

    Zombie_Striker

    @Richard12799
    A player has to have been in the world before you can access the world. If you do that and it still is null, then post what your code.
     
  3. Offline

    Richard12799

    @Zombie_Striker How would I "put" a player in a world when the server is booting up?
     
  4. Offline

    Zombie_Striker

    @Richard12799
    Can't. No players are online, or if there are, they won't update the world. You have to wait a few ticks/seconds untill either someone joins or the world updates in some way.

    I would recommend creating a repeating task. Every couple of ticks, check if the world is null. Once it is no longer null, do your thing.
     
  5. Offline

    Richard12799

    @Zombie_Striker Ok and there's no other way? I am loading Parkour maps from a config but the start position becomes null when the World doesn't exist.

    I don't think that method would work because if someone joins and tries to start a parkour whose start position is in a world that no player has been in yet, it won't let them.
     
  6. Offline

    Zombie_Striker

    @Richard12799
    If this does not work, you may have to use a WorldCreator to "recreate"/re-load the world. If you have to, use :
    Code:
        WorldCreator worldCreator = new WorldCreator("WORLD NAME");    
        Bukkit.getServer().createWorld(worldCreator);
     
  7. Offline

    timtower Administrator Administrator Moderator

    Moved to plugin development.
    @Richard12799 You could also listen to the world load event. If the world gets loaded by a multiworld plugin then you will know about it.
     
Thread Status:
Not open for further replies.

Share This Page