Make thread requirements of ReplayHandler#setup explicit and fix illegal usage

This commit is contained in:
Jonas Herzig
2019-07-08 09:53:47 +02:00
parent 8261767657
commit c4d2be9e89
2 changed files with 16 additions and 17 deletions

View File

@@ -845,11 +845,11 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
startFromBeginning = false;
nextPacket = null;
lastPacketSent = System.currentTimeMillis();
replayHandler.restartedReplay();
if (replayIn != null) {
replayIn.close();
replayIn = null;
}
ReplayMod.instance.runSync(replayHandler::restartedReplay);
}
}
} catch (Exception e) {

View File

@@ -161,25 +161,22 @@ public class ReplayHandler {
}
void restartedReplay() {
Preconditions.checkState(isOnMainThread(), "Must be called from Minecraft thread.");
channel.close();
//#if MC>=11300
mc.mouse.unlockCursor();
//#else
//$$ mc.setIngameNotInFocus();
//#endif
// Force re-creation of camera entity by unloading the previous world
try {
ReplayMod.instance.runSync(() -> {
//#if MC>=11300
mc.mouse.unlockCursor();
//#else
//$$ mc.setIngameNotInFocus();
//#endif
//#if MC>=11400
mc.disconnect();
//#else
//$$ mc.loadWorld(null);
//#endif
});
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.error("Failed to properly restart (shutdown) replay:", e);
}
//#if MC>=11400
mc.disconnect();
//#else
//$$ mc.loadWorld(null);
//#endif
restrictions = new Restrictions();
@@ -236,6 +233,8 @@ public class ReplayHandler {
}
private void setup() {
Preconditions.checkState(isOnMainThread(), "Must be called from Minecraft thread.");
//#if MC>=11100
mc.inGameHud.getChatHud().clear(false);
//#else