Make sure the replay is stopped if the main menu is opened (fixes #95)

This commit is contained in:
Jonas Herzig
2018-01-16 16:14:03 +01:00
parent d7368d8c87
commit 22e4ce4584
2 changed files with 20 additions and 0 deletions

View File

@@ -16,6 +16,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static com.replaymod.replay.ReplayModReplay.LOGGER;
public class GuiHandler {
private static final int BUTTON_EXIT_SERVER = 1;
private static final int BUTTON_ACHIEVEMENTS = 5;
@@ -102,6 +104,20 @@ public class GuiHandler {
return;
}
if (mod.getReplayHandler() != null) {
// Something went terribly wrong and we ended up in the main menu with the replay still active.
// To prevent players from joining live servers and using the CameraEntity, try to stop the replay now.
try {
mod.getReplayHandler().endReplay();
} catch (IOException e) {
LOGGER.error("Trying to stop broken replay: ", e);
} finally {
if (mod.getReplayHandler() != null) {
mod.forcefullyStopReplay();
}
}
}
@SuppressWarnings("unchecked")
List<GuiButton> buttonList = event.buttonList;
GuiButton button = new GuiButton(BUTTON_REPLAY_VIEWER, event.gui.width / 2 - 100,