Forced Save on Shut Down

Discussion in 'Plugin Development' started by TheDummy, Aug 9, 2014.

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

    TheDummy

    Background:
    My plugin has "temporary" entities it spawns into the world at various times. They are removed when the server shuts down. Normally, as the plugin is being disabled, the entities are removed from the world. Once all plugins are disabled, the world is saved normally like Bukkit does.

    Situation:
    However, one of the testers for my plugin uses the MultiCraft panel and it does a force save before disabling all plugins. From what I can tell, if the server is stopped in game by a player (in which case MultiCraft doesn't do a force save), the plugin removes entities as intended and do not appear after the restart.

    If the plugins are disabled using the stop command in MultiCraft, the plugin will remove entities, but they will be back once the server restarts (even though there's the default world save from Bukkit).

    My question is:
    What would be the best way to ensure that the entities are removed for sure so that they don't appear again after a restart? Is it possible to force a world save as the plugin is being disabled in order to overwrite the Multicraft save?
     
  2. Offline

    chaseoes

    Save the world again after you remove them?
     
  3. Offline

    TheDummy

    chaseoes I did:

    Code:java
    1. World toSave = Bukkit.getWorld( "world" );
    2. toSave.save();


    But it did not work in removing the entities by the next startup.
     
  4. Offline

    chaseoes

    The server automatically saves chunks when it's shut down, after all plugins are disabled, and regardless of how it's shut down (assuming the process isn't killed) -- so it sounds like you have a different issue.
     
  5. Offline

    TheDummy

    chaseoes I decompiled the Bukkit jar to see the implementation for the world.save() function. It queues up chunks to save (perhaps in the next server tick), but doesn't actually save them. I used the world.unload( x, z ) function to force save the chunk with the entity as my plugin was being disabled and it fixed the problem.

    If someone could explain why it worked, that would be very helpful.
     
Thread Status:
Not open for further replies.

Share This Page