So forge gets angry when you put “System.exit()” in your code, and says it will reroute to FMLCommonHandler.exitJava, now my question is, since in sponge we can’t access this class, how would I do an equivalent System.exit, within my plugins constructor.
I want to be able to do this because a certain fatal error may occur which causes my plugin to crash the server anyway, and I want to catch the error, print a message, and terminate the program instead.
Plugins are not responsible for handling the game’s lifecycle.
If you want to catch an error that may occur during construction then just wrap a try-catch around it.
You should just stop your plugin from loading, but it it’s necessary to stop the server there’s Sponge.getServer().shutdown()
But is the server object available during plugin constructor. The docs are a bit vague, and I was under the assumption it wasn’t.
I’m not sure what the best solution would be, perhaps set some sort of invalidated
flag if an error occurs during construction, then when the server has loaded (GameStartedServerEvent
) if invalidated
is true
then shutdown.
I generally just unregister all listeners and commands. No reason to kill the server.
1 Like