Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

  • 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.

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.

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.

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.

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.