Skip to content

Commit

Permalink
When the window is closed during loading, exit the game quickly (Mine…
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz authored and LexManos committed May 2, 2017
1 parent 91cc592 commit e4d04af
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,12 @@ public boolean isLoading()
return loading;
}

@Override
public boolean isDisplayCloseRequested()
{
return Display.isCreated() && Display.isCloseRequested();
}

@Override
public boolean shouldServerShouldBeKilledQuietly()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ public void confirmBackupLevelDatUse(SaveHandler handler)
if (!confirmed) StartupQuery.abort();
}

public boolean isDisplayCloseRequested()
{
return sidedDelegate != null && sidedDelegate.isDisplayCloseRequested();
}

public boolean shouldServerBeKilledQuietly()
{
if (sidedDelegate == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public interface IFMLSidedHandler

MinecraftServer getServer();

boolean isDisplayCloseRequested();

boolean shouldServerShouldBeKilledQuietly();

void addModAsResource(ModContainer container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ public void distributeStateMessage(LoaderState state, Object... eventData)

public void transition(LoaderState desiredState, boolean forceState)
{
if (FMLCommonHandler.instance().isDisplayCloseRequested())
{
FMLLog.info("The game window is being closed by the player, exiting.");
FMLCommonHandler.instance().exitJava(0, false);
}

LoaderState oldState = state;
state = state.transition(!errors.isEmpty());
if (state != desiredState && !forceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ else if (cmd.equals("/stop"))
}
}

@Override
public boolean isDisplayCloseRequested()
{
return false;
}

@Override
public boolean shouldServerShouldBeKilledQuietly()
{
Expand Down

0 comments on commit e4d04af

Please sign in to comment.