Jump to content

[1.8] Run code on final exit before world save


big_red_frog

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.