Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

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.