DataListener Shutdown Hook only does its job if the Replay hasn't been saved before. This prevents the Replay from being corrupted when quitting Minecraft.

This commit is contained in:
CrushedPixel
2015-06-02 20:42:39 +02:00
parent 539b7da738
commit 484f8fab02

View File

@@ -37,6 +37,8 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
private boolean singleplayer; private boolean singleplayer;
private Gson gson = new Gson(); private Gson gson = new Gson();
private int saveState = 0; //0: Idle, 1: Saving, 2: Saved
private final File tempResourcePacksFolder = Files.createTempDir(); private final File tempResourcePacksFolder = Files.createTempDir();
private final Map<Integer, String> requestToHash = new ConcurrentHashMap<Integer, String>(); private final Map<Integer, String> requestToHash = new ConcurrentHashMap<Integer, String>();
private final Map<String, File> resourcePacks = new HashMap<String, File>(); private final Map<String, File> resourcePacks = new HashMap<String, File>();
@@ -58,7 +60,7 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
@Override @Override
public void run() { public void run() {
try { try {
if(DataListener.this.alive) { if(saveState == 0) {
System.out.println("Saving Replay File to prevent Corruption"); System.out.println("Saving Replay File to prevent Corruption");
DataListener.this.channelInactive(null); DataListener.this.channelInactive(null);
} }
@@ -156,6 +158,7 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
try { try {
ReplayMod.replayFileAppender.startNewReplayFileWriting(); ReplayMod.replayFileAppender.startNewReplayFileWriting();
saveState = 1;
String mcversion = Minecraft.getMinecraft().getVersion(); String mcversion = Minecraft.getMinecraft().getVersion();
String[] split = mcversion.split("-"); String[] split = mcversion.split("-");
@@ -183,6 +186,7 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
ReplayMod.replayFileAppender.replayFileWritingFinished(); ReplayMod.replayFileAppender.replayFileWritingFinished();
saveState = 2;
} }
} }