Replay Files that are published on ReplayMod.com are now downloadable
This commit is contained in:
@@ -7,6 +7,7 @@ import eu.crushedpixel.replaymod.localization.LocalizedResourcePack;
|
|||||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||||
|
import eu.crushedpixel.replaymod.registry.DownloadedFileHandler;
|
||||||
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
|
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
|
||||||
import eu.crushedpixel.replaymod.registry.ReplayFileAppender;
|
import eu.crushedpixel.replaymod.registry.ReplayFileAppender;
|
||||||
import eu.crushedpixel.replaymod.registry.UploadedFileHandler;
|
import eu.crushedpixel.replaymod.registry.UploadedFileHandler;
|
||||||
@@ -66,6 +67,7 @@ public class ReplayMod {
|
|||||||
public static int TP_DISTANCE_LIMIT = 128;
|
public static int TP_DISTANCE_LIMIT = 128;
|
||||||
public static ReplayFileAppender replayFileAppender;
|
public static ReplayFileAppender replayFileAppender;
|
||||||
public static UploadedFileHandler uploadedFileHandler;
|
public static UploadedFileHandler uploadedFileHandler;
|
||||||
|
public static DownloadedFileHandler downloadedFileHandler;
|
||||||
|
|
||||||
private static Field defaultResourcePacksField;
|
private static Field defaultResourcePacksField;
|
||||||
static {
|
static {
|
||||||
@@ -92,6 +94,8 @@ public class ReplayMod {
|
|||||||
replaySettings = new ReplaySettings();
|
replaySettings = new ReplaySettings();
|
||||||
replaySettings.readValues();
|
replaySettings.readValues();
|
||||||
|
|
||||||
|
downloadedFileHandler = new DownloadedFileHandler();
|
||||||
|
|
||||||
replayFileAppender = new ReplayFileAppender();
|
replayFileAppender = new ReplayFileAppender();
|
||||||
replayFileAppender.start();
|
replayFileAppender.start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import eu.crushedpixel.replaymod.gui.GuiConstants;
|
|||||||
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListEntry;
|
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListEntry;
|
||||||
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
|
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
|
||||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||||
|
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||||
import net.minecraft.client.gui.*;
|
import net.minecraft.client.gui.*;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
@@ -149,7 +150,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
|||||||
GuiReplayListEntry entry = currentList.getListEntry(index);
|
GuiReplayListEntry entry = currentList.getListEntry(index);
|
||||||
FileInfo info = entry.getFileInfo();
|
FileInfo info = entry.getFileInfo();
|
||||||
if(info != null) {
|
if(info != null) {
|
||||||
boolean downloaded = false;
|
boolean downloaded = ReplayMod.downloadedFileHandler.getFileForID(info.getId()) != null;
|
||||||
loadButton.displayString = downloaded ? I18n.format("replaymod.gui.load") : I18n.format("replaymod.gui.download");
|
loadButton.displayString = downloaded ? I18n.format("replaymod.gui.load") : I18n.format("replaymod.gui.download");
|
||||||
loadButton.enabled = true;
|
loadButton.enabled = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -177,7 +178,19 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
|||||||
} else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) {
|
} else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) {
|
||||||
|
|
||||||
} else if(button.id == GuiConstants.CENTER_LOAD_REPLAY_BUTTON) {
|
} else if(button.id == GuiConstants.CENTER_LOAD_REPLAY_BUTTON) {
|
||||||
|
GuiReplayListEntry entry = currentList.getListEntry(currentList.selected);
|
||||||
|
FileInfo info = entry.getFileInfo();
|
||||||
|
if(info != null) {
|
||||||
|
File f = ReplayMod.downloadedFileHandler.getFileForID(info.getId());
|
||||||
|
if(f == null) {
|
||||||
|
f = ReplayMod.downloadedFileHandler.downloadFileForID(info.getId());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ReplayHandler.startReplay(f);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package eu.crushedpixel.replaymod.registry;
|
package eu.crushedpixel.replaymod.registry;
|
||||||
|
|
||||||
import eu.crushedpixel.replaymod.ReplayMod;
|
import eu.crushedpixel.replaymod.ReplayMod;
|
||||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||||
|
import eu.crushedpixel.replaymod.utils.ReplayFile;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -29,9 +30,14 @@ public class DownloadedFileHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File generateFileForID(int id) {
|
||||||
|
return new File(downloadFolder, id+"."+ ReplayFile.ZIP_FILE_EXTENSION);
|
||||||
|
}
|
||||||
|
|
||||||
public void addToIndex(int id) {
|
public void addToIndex(int id) {
|
||||||
try {
|
try {
|
||||||
File f = new File(downloadFolder, id+"."+ConnectionEventHandler.ZIP_FILE_EXTENSION);
|
File f = generateFileForID(id);
|
||||||
|
if(f.exists()) downloadedFiles.put(id, f);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -40,4 +46,20 @@ public class DownloadedFileHandler {
|
|||||||
public File getFileForID(int id) {
|
public File getFileForID(int id) {
|
||||||
return downloadedFiles.get(id);
|
return downloadedFiles.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File downloadFileForID(int id) {
|
||||||
|
File f = getFileForID(id);
|
||||||
|
if(f != null) return f;
|
||||||
|
|
||||||
|
f = generateFileForID(id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ReplayMod.apiClient.downloadFile(AuthenticationHandler.getKey(), id, f);
|
||||||
|
addToIndex(id);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user