Allow a clean way to exit the game without big ugly warnings, but with logging information available if needed. Closes #496

This commit is contained in:
cpw 2014-08-15 16:16:07 -04:00
parent 1d336e0aa7
commit 4692e66389
1 changed files with 33 additions and 0 deletions

View File

@ -594,4 +594,37 @@ public class FMLCommonHandler
{
return sidedDelegate.shouldAllowPlayerLogins();
}
/**
* Used to exit from java, with system exit preventions in place. Will be tidy about it and just log a message,
* unless debugging is enabled
*
* @param exitCode The exit code
* @param hardExit Perform a halt instead of an exit (only use when the world is unsavable)
*/
public void exitJava(int exitCode, boolean hardExit)
{
FMLLog.log(Level.INFO, "Java has been asked to exit (code %d) by %s.", exitCode, Thread.currentThread().getStackTrace()[1]);
if (hardExit)
{
FMLLog.log(Level.INFO, "This is a forced exit");
}
if (Boolean.parseBoolean(System.getProperty("fml.debugExit", "false")))
{
FMLLog.log(Level.INFO, new Throwable(), "Exit trace");
}
else
{
FMLLog.log(Level.INFO, "If this was an unexpected exit, use -Dfml.debugExit=true to find out where it was called");
}
if (hardExit)
{
Runtime.getRuntime().halt(exitCode);
}
else
{
System.exit(exitCode);
}
}
}