Solved Getting a world which isn't yet loaded.

Discussion in 'Plugin Development' started by the_merciless, Sep 8, 2013.

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

    the_merciless

    I'm trying to load a location which is saved in the config, but the world keeps returning null. Im guessing because it isn't yet loaded.

    Config looks like:

    Code:
    XpBlocks:
      Block1:
        world: merci
        x: -848.0
        y: 69.0
        z: -599.0
    
    and the code to make the location:

    Code:
    @Override
        public void onEnable(){
            getLogger().info(" has been enabled");
            getLogger().info(" written by The_Merciless");
            getServer().getPluginManager().registerEvents(this, this);
       
            if (!new File(getDataFolder(), "config.yml").exists()) {
                saveConfig();
            }
       
            Configuration config = getConfig();
            if (config.contains("XpBlocks")){
                for (String string : getConfig().getConfigurationSection("XpBlocks").getKeys(false)){
                    String worldname = config.getString("XpBlocks." + string + ".world");
                    getLogger().info(" worldname found in config - " + worldname);
                    World w = Bukkit.getWorld(worldname); //THIS LINE IS RETURNING NULL
                    int x = config.getInt("XpBlocks." + string + ".x");
                    int y = config.getInt("XpBlocks." + string + ".y");
                    int z = config.getInt("XpBlocks." + string + ".z");
                    Location loc = new Location(w,x,y,z);
                    locations.add(loc);
                    getLogger().info(" Location loaded - " + loc);
                }       
            }
        }
    The first debug returns the world name, the last returns a location with the world showing null

    Solved - Solution is here if you need it

    https://forums.bukkit.org/threads/load-a-world.103355/#post-1356101

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. Offline

    TheSmallBones

  3. Offline

    the_merciless

    I thought the worlds get loaded before onenable so i was expecting someone to point out a mistake in my code. Hence i never googled how to force load a world.

    None of your links provided a solution to my problem anyway.
     
Thread Status:
Not open for further replies.

Share This Page