World Unloading

Discussion in 'Plugin Development' started by Zupsub, Jul 21, 2014.

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

    Zupsub

    I have a few questions about world unloading. So when is a world unloaded? Only when the server stops, restarts, every chunk is unloaded, no players are in this world for x minutes or ...

    Then whats the difference between WorldSave- and WorldUnload event? Isn't a world only and always saved when it will unload?
     
  2. Offline

    LugnutsK

    A world can be unloaded and not saved (changes will be lost)
     
  3. Offline

    stonar96

    I had many problems with world unloading too. To unload a world just use:
    Code:java
    1. plugin.getServer().unloadWorld(worldName, true);


    I had problems when I set the boolean save to false, because the world didn't unload completely. You can't unload a world as long as there are players in the world. That means that you have to teleport all players to another world beforeunloading and you have to force dead player to respawn before you teleport them.

    Code:java
    1. for (Player p : world.getPlayers()) {
    2. if (p.isDead()) {
    3. ((CraftPlayer) p).getHandle().playerConnection.a(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN));
    4. }
    5. }
    6.  
    7. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    8. public void run() {
    9. for (Player p : world.getPlayers()) {
    10. p.teleport(l);
    11. }
    12.  
    13. plugin.getServer().unloadWorld(world.getName(), true);
    14. }
    15. }, 20L);


    The world should be completely unloaded after this code
     
  4. Offline

    stormneo7

    Nope. You can unload a world and not save it.
    [​IMG]
     
  5. Offline

    hintss

    I'd imagine it's also possible to save a world without unloading it?
     
  6. Offline

    daavko

    hintss Yep, it's
    Code:java
    1. <some world>.save();

    :D
     
  7. Offline

    Zupsub

    Ok, thx, the second question is completely answered. :)

    But I need to know, when a world is unloaded automatically? On /reload or when the server /stop s or ...
     
  8. Offline

    daavko

    Zupsub I think world is auto-unloaded when:
    /stop is called, last player in that world switches to another world or disconnects, some plugin calls <world>.unload(boolean save), and there may be more, but I can't think of anything more right now.
     
Thread Status:
Not open for further replies.

Share This Page