Posted December 6, 20159 yr 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?
December 7, 20159 yr Author 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.
December 7, 20159 yr 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. I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.
December 7, 20159 yr 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... I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.
December 7, 20159 yr Well that makes sense.. @OP, why do you need to call code when a local game closes? I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.
December 10, 20159 yr Author 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.
December 10, 20159 yr 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(); } I think its my java of the variables.
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.