I don't understand my problem with worlds

Discussion in 'Plugin Development' started by leluckyyDE, Sep 28, 2019.

  1. Offline

    leluckyyDE

    First of all sorry for my bad english skills.

    My problem is that I've programmed a worldmanager, but every time I've created a world and my server is restarting it's not there anymore for the server as world, just as a folder. I don't know how to fix it. If it helps, here is my method: https://pastebin.com/Lu3FqFrx

    Thanks for every help <3
     
  2. Offline

    DerDonut

    I don't know how your plugin works but do you load all your worlds on the restart? The server just loads the main world when starting. The others are just folders until you load them. (As far as I know)
     
    leluckyyDE likes this.
  3. Online

    robertlit

    Everytime you shuts down the server the worlds get unloaded, when the server comes back up the only worlds that are loaded are the overworld, the nether, and the end. Every other world needs to be manually loaded by a plugin.
    What I would recommend doing is, everytime the command is run, add the world name to an array in a yml file, that way all of the custom world names are stored, and in your onEnable() method you would just loop through them and load them with something like this:
    Code:
    ArrayList<String> worlds = getWorldsFile().getList("worlds");
    for (String world : worlds) {
    WorldCreator wc = new WorldCreator(world);
    wc.createWorld();
    }
    Don't worry it will not delete the world and put a new one it will just load the world!

    (Of course getWorldsFile() should be defined and return the yml file. If you are not experienced with custom yml configuration files I would recommend checking this https://www.spigotmc.org/wiki/config-files/)

    @leluckyyDE Hope it helped, Robert.
     
    Last edited: Oct 1, 2019
    leluckyyDE likes this.
  4. Offline

    leluckyyDE

    @robertlit Thank you but why it doesn't work with Bukkit.getWorlds().add(world);
     
  5. Online

    robertlit

    @leluckyyDE You misunderstood me.. This obviously wouldn't work because adding a world to an arraylist won't load it.. What I meant is that everytime the command to add a world is run you will save the world name in an arraylist inside yml file and then in the class that extends JavaPlugin in the onEnable method you will load them (see example in previous post).. Do you know how yml files work and how to interact with them via bukkit? (If not check the link in the previous post)
    If you have anymore problems @ me :D
     
    Last edited: Oct 2, 2019
  6. Offline

    leluckyyDE

Share This Page