big_red_frog Posted December 6, 2015 Share Posted December 6, 2015 Hi All, When the server is going to shut down as the player has left, and this is a local game, I want to call a method in one of my classes to ensure that the world gets certain blocks removed / modified. They come from live external data and are added and removed in real time. So a user coming back hours later presently sees blocks that did not get removed in the normal lifecycle, but instead got saved. If I can call a method pre save, on exit, then I will be able to flush out all the blocks that I do not want to be present hours later. Where would I be able to call such a method from? Quote Link to comment Share on other sites More sharing options...
big_red_frog Posted December 7, 2015 Author Share Posted December 7, 2015 Actually I might be out of luck here. If the world save's pre-emptively when you go to the menu, I can't do things in that transition as I don't want to unnecessarily remove blocks when you pause. Then modifying the block content on unload, will not actually cause the result to be saved, as the world already is and the system just exits :-( So I think I will leave it for now, and maybe come back to it, when I understand the general lifecycle better. Quote Link to comment Share on other sites More sharing options...
ovikk Posted December 7, 2015 Share Posted December 7, 2015 Correct me if I'm wrong.. But there is a fml life cycle event called FMLServerStoppedEvent. You would call it like this in the main class: @EventHandler public void serverStopped(FMLServerStoppedEvent event) { //code in here } If that runs just to late, you could also try the FMLServerStoppingEvent. Quote I might be terribly wrong.. Like really, really wrong. But I'm just trying to help. Link to comment Share on other sites More sharing options...
ovikk Posted December 7, 2015 Share Posted December 7, 2015 But "the server is stopping" is not the same as "all worlds are unloading". Dimensions might very well be unloaded (and reloaded) before then. What? I thoght the OP wanted his code to run when the world stops, not when it starts... Quote I might be terribly wrong.. Like really, really wrong. But I'm just trying to help. Link to comment Share on other sites More sharing options...
ovikk Posted December 7, 2015 Share Posted December 7, 2015 Well that makes sense.. @OP, why do you need to call code when a local game closes? Quote I might be terribly wrong.. Like really, really wrong. But I'm just trying to help. Link to comment Share on other sites More sharing options...
big_red_frog Posted December 10, 2015 Author Share Posted December 10, 2015 To flush out changes to the world blocks driven by realtime data from an external source. Worst case I could persist the undelying data and flush on reload, but that feels wrong, I dont really want to persist that data just for post load cleanup. Quote Link to comment Share on other sites More sharing options...
RANKSHANK Posted December 10, 2015 Share Posted December 10, 2015 Exactly. And worlds can stop without the server stopping. Is there a way to parse through the loaded worlds? Something like public void foo(WorldEvent.Unload e){ if(Server.listWorlds.size() == 1) myShit.flush(); } Quote I think its my java of the variables. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.