Solved getWorlds() only returns default world?

Discussion in 'Plugin Development' started by Flamedek, Jun 18, 2014.

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

    Flamedek

    Hi, I'm trying to get all worlds of the server on startup to add to a (config)file.
    However it only finds the main, default world and none of the others.

    This is the code, called in onEnable()
    Code:java
    1. private void generateConfig() {
    2. final FileConfiguration config = getConfig();
    3. for(World world : getServer().getWorlds()) {
    4. String name = world.getName();
    5. if(!config.contains(name)) {
    6. config.addDefault(name + ".noBlockUpdates", false);
    7. config.addDefault(name + ".alsoNoLiquidFlow", false);
    8. }
    9. }
    10. config.options().copyDefaults(true);
    11. saveConfig();
    12. }


    I am using multiverse for handling the worlds, could that be an issue?
     
  2. Offline

    flaaghara

    I haven't used Multiverse in a while but I believe that the worlds may be stored differently (not being in the main folder)? Regardless, MV has an API that you can use.

    http://ci.onarandombox.com/job/Multiverse-Core/doxygen/ has methods for interacting with Multiverse. However, keep in mind that if you base your plugin off of Multiverse world storage then the plugin will be incompatible with non-users of MV. The workaround is to use a boolean which tracks whether MV is being used or not abd be able to handle MV and non-MV servers.

    On that link I gave you can call a MVWorldManager object. That has methods for getting Collections of Worlds, Worlds by name, etc.
     
  3. Offline

    Flamedek

    flaaghara Ah I didn't get an alert :/
    Anyway, I found a workaround that 'should' be compatible with both MV users and non MV users.

    Inside onEnable() it will always just find the default world. So in there I use getServer().getWorlds().get(0) which should always return that world.
    Then for the other worlds I found the WorldLoadEvent. I don't know if it is because MV or not, but that is fired once for every world on startup (after the plugins are enabled). With these combined I can get every world.

    The only issue is that is doesn't handle reloads very well. As plugins are reloaded but worlds are not and thus the WorldLoadEvents are not called. But overall I still think this is a good solution.

    Thank you for thinking along :)
     
Thread Status:
Not open for further replies.

Share This Page