Whenever a Replay File is being written or modified and the user is not in-game, a GuiReplaySaving is opened and asks him to wait
This commit is contained in:
@@ -68,14 +68,12 @@ public class GuiEventHandler {
|
|||||||
if(ReplayHandler.isInReplay()) ReplayHandler.setInReplay(false);
|
if(ReplayHandler.isInReplay()) ReplayHandler.setInReplay(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!AuthenticationHandler.isAuthenticated()) return;
|
if(event.gui != null && ReplayMod.replayFileAppender.isBusy() && !allowedGUIs.contains(event.gui.getClass())) {
|
||||||
|
|
||||||
/*
|
|
||||||
if(event.gui != null && GuiReplaySaving.replaySaving && !allowedGUIs.contains(event.gui.getClass())) {
|
|
||||||
event.gui = new GuiReplaySaving(event.gui);
|
event.gui = new GuiReplaySaving(event.gui);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
if(!AuthenticationHandler.isAuthenticated()) return;
|
||||||
|
|
||||||
if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) {
|
if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) {
|
||||||
if(ReplayHandler.isInReplay()) {
|
if(ReplayHandler.isInReplay()) {
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package eu.crushedpixel.replaymod.gui;
|
package eu.crushedpixel.replaymod.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class GuiReplaySaving extends GuiScreen {
|
public class GuiReplaySaving extends GuiScreen {
|
||||||
|
|
||||||
private GuiScreen waiting = null;
|
private GuiScreen waiting = null;
|
||||||
|
|
||||||
|
private final Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
public GuiReplaySaving(GuiScreen waiting) {
|
public GuiReplaySaving(GuiScreen waiting) {
|
||||||
this.waiting = waiting;
|
this.waiting = waiting;
|
||||||
}
|
}
|
||||||
@@ -23,4 +28,8 @@ public class GuiReplaySaving extends GuiScreen {
|
|||||||
mc.displayGuiScreen(waiting);
|
mc.displayGuiScreen(waiting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||||
|
//Ignore key inputs to disallow users from closing this GUI
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package eu.crushedpixel.replaymod.recording;
|
|||||||
import com.google.common.hash.Hashing;
|
import com.google.common.hash.Hashing;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import eu.crushedpixel.replaymod.ReplayMod;
|
||||||
import eu.crushedpixel.replaymod.holders.PacketData;
|
import eu.crushedpixel.replaymod.holders.PacketData;
|
||||||
import eu.crushedpixel.replaymod.utils.ReplayFile;
|
import eu.crushedpixel.replaymod.utils.ReplayFile;
|
||||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||||
@@ -17,7 +18,6 @@ import java.io.*;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
@@ -48,8 +48,6 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
|||||||
this.worldName = worldName;
|
this.worldName = worldName;
|
||||||
this.singleplayer = singleplayer;
|
this.singleplayer = singleplayer;
|
||||||
|
|
||||||
System.out.println(worldName);
|
|
||||||
|
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||||
DataOutputStream out = new DataOutputStream(bos);
|
DataOutputStream out = new DataOutputStream(bos);
|
||||||
@@ -58,7 +56,6 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
|||||||
|
|
||||||
public void setWorldName(String worldName) {
|
public void setWorldName(String worldName) {
|
||||||
this.worldName = worldName;
|
this.worldName = worldName;
|
||||||
System.out.println(worldName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,13 +85,12 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
|||||||
|
|
||||||
private ConcurrentLinkedQueue<PacketData> queue = new ConcurrentLinkedQueue<PacketData>();
|
private ConcurrentLinkedQueue<PacketData> queue = new ConcurrentLinkedQueue<PacketData>();
|
||||||
private DataOutputStream stream;
|
private DataOutputStream stream;
|
||||||
|
|
||||||
Thread outputThread = new Thread(new Runnable() {
|
Thread outputThread = new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
HashMap<Class, Integer> counts = new HashMap<Class, Integer>();
|
|
||||||
|
|
||||||
while(active) {
|
while(active) {
|
||||||
PacketData dataReciever = queue.poll();
|
PacketData dataReciever = queue.poll();
|
||||||
if(dataReciever != null) {
|
if(dataReciever != null) {
|
||||||
@@ -128,10 +124,6 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Entry<Class, Integer> entries : counts.entrySet()) {
|
|
||||||
System.out.println(entries.getKey() + "| " + entries.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}, "replaymod-packet-writer");
|
}, "replaymod-packet-writer");
|
||||||
|
|
||||||
@@ -148,6 +140,8 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
|||||||
active = false;
|
active = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
ReplayMod.replayFileAppender.startNewReplayFileWriting();
|
||||||
|
|
||||||
String mcversion = Minecraft.getMinecraft().getVersion();
|
String mcversion = Minecraft.getMinecraft().getVersion();
|
||||||
String[] split = mcversion.split("-");
|
String[] split = mcversion.split("-");
|
||||||
if(split.length > 0) {
|
if(split.length > 0) {
|
||||||
@@ -157,7 +151,6 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
|||||||
String[] pl = players.toArray(new String[players.size()]);
|
String[] pl = players.toArray(new String[players.size()]);
|
||||||
|
|
||||||
ReplayMetaData metaData = new ReplayMetaData(singleplayer, worldName, (int) lastSentPacket, startTime, pl, mcversion);
|
ReplayMetaData metaData = new ReplayMetaData(singleplayer, worldName, (int) lastSentPacket, startTime, pl, mcversion);
|
||||||
String json = gson.toJson(metaData);
|
|
||||||
|
|
||||||
File folder = ReplayFileIO.getReplayFolder();
|
File folder = ReplayFileIO.getReplayFolder();
|
||||||
|
|
||||||
@@ -171,6 +164,8 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
|||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
ReplayMod.replayFileAppender.replayFileWritingFinished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package eu.crushedpixel.replaymod.registry;
|
package eu.crushedpixel.replaymod.registry;
|
||||||
|
|
||||||
|
import eu.crushedpixel.replaymod.gui.GuiReplaySaving;
|
||||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
@@ -12,6 +16,31 @@ public class ReplayFileAppender extends Thread {
|
|||||||
|
|
||||||
private Queue<Pair<Pair<File, String>, File>> filesToMove = new ConcurrentLinkedQueue<Pair<Pair<File, String>, File>>();
|
private Queue<Pair<Pair<File, String>, File>> filesToMove = new ConcurrentLinkedQueue<Pair<Pair<File, String>, File>>();
|
||||||
private boolean shutdown = false;
|
private boolean shutdown = false;
|
||||||
|
private List<GuiReplaySaving> listeners = new ArrayList<GuiReplaySaving>();
|
||||||
|
|
||||||
|
//this is true if the DataListener is currently busy saving a newly recorded Replay File
|
||||||
|
private boolean newReplayFileWriting = false;
|
||||||
|
|
||||||
|
public void startNewReplayFileWriting() {
|
||||||
|
newReplayFileWriting = true;
|
||||||
|
|
||||||
|
if(!FMLClientHandler.instance().isGUIOpen(GuiReplaySaving.class)) {
|
||||||
|
Minecraft.getMinecraft().addScheduledTask(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
final GuiReplaySaving savingScreen = new GuiReplaySaving(null);
|
||||||
|
addFinishListener(savingScreen);
|
||||||
|
|
||||||
|
Minecraft.getMinecraft().displayGuiScreen(savingScreen);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replayFileWritingFinished() {
|
||||||
|
newReplayFileWriting = false;
|
||||||
|
callListeners();
|
||||||
|
}
|
||||||
|
|
||||||
public ReplayFileAppender() {
|
public ReplayFileAppender() {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||||
@@ -36,6 +65,14 @@ public class ReplayFileAppender extends Thread {
|
|||||||
shutdown = true;
|
shutdown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isBusy() {
|
||||||
|
return !filesToMove.isEmpty() && !newReplayFileWriting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFinishListener(GuiReplaySaving gui) {
|
||||||
|
listeners.add(gui);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while(!shutdown || !filesToMove.isEmpty()) {
|
while(!shutdown || !filesToMove.isEmpty()) {
|
||||||
@@ -47,6 +84,8 @@ public class ReplayFileAppender extends Thread {
|
|||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
filesToMove.add(mv);
|
filesToMove.add(mv);
|
||||||
|
} finally {
|
||||||
|
callListeners();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
filesToMove.add(mv);
|
filesToMove.add(mv);
|
||||||
@@ -58,4 +97,19 @@ public class ReplayFileAppender extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void callListeners() {
|
||||||
|
if(filesToMove.isEmpty() && !newReplayFileWriting) {
|
||||||
|
for(final GuiReplaySaving gui : listeners) {
|
||||||
|
Minecraft.getMinecraft().addScheduledTask(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
gui.dispatch();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
listeners = new ArrayList<GuiReplaySaving>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user