diff --git a/src/main/java/eu/crushedpixel/replaymod/api/client/ApiClient.java b/src/main/java/eu/crushedpixel/replaymod/api/client/ApiClient.java index b79e432c..b5b38bea 100644 --- a/src/main/java/eu/crushedpixel/replaymod/api/client/ApiClient.java +++ b/src/main/java/eu/crushedpixel/replaymod/api/client/ApiClient.java @@ -18,6 +18,7 @@ import com.google.gson.JsonParser; import eu.crushedpixel.replaymod.api.client.holders.ApiError; import eu.crushedpixel.replaymod.api.client.holders.AuthKey; import eu.crushedpixel.replaymod.api.client.holders.FileInfo; +import eu.crushedpixel.replaymod.api.client.holders.SearchResult; import eu.crushedpixel.replaymod.api.client.holders.Success; import eu.crushedpixel.replaymod.api.client.holders.UserFiles; import eu.crushedpixel.replaymod.utils.StreamTools; @@ -54,21 +55,19 @@ public class ApiClient { QueryBuilder builder = new QueryBuilder(ApiMethods.replay_files); builder.put("auth", auth); builder.put("ids", buildListString(ids)); - FileInfo[] info = invokeAndReturn(builder, FileInfo[].class); //TODO: Test if that works + FileInfo[] info = invokeAndReturn(builder, FileInfo[].class); return info; } - public FileInfo[] getRecentFiles() throws IOException, ApiException { - QueryBuilder builder = new QueryBuilder(ApiMethods.replay_files); - builder.put("recent", true); - FileInfo[] info = invokeAndReturn(builder, FileInfo[].class); //TODO: Test if that works - return info; - } - - public FileInfo[] getBestFiles() throws IOException, ApiException { - QueryBuilder builder = new QueryBuilder(ApiMethods.replay_files); - builder.put("best", true); - FileInfo[] info = invokeAndReturn(builder, FileInfo[].class); //TODO: Test if that works + public FileInfo[] searchFiles(SearchQuery query) throws IOException, ApiException { + StringBuilder sb = new StringBuilder(); + + // build base url + sb.append(QueryBuilder.API_BASE_URL); + sb.append("search"); + sb.append(query.buildQuery()); + + FileInfo[] info = invokeAndReturn(sb.toString(), SearchResult.class).getResults(); return info; } @@ -116,8 +115,12 @@ public class ApiClient { invokeAndReturn(builder, Success.class); } - private T invokeAndReturn(QueryBuilder builder,Class classOfT) throws IOException, ApiException { - JsonElement ele = GsonApiClient.invoke(builder); + private T invokeAndReturn(QueryBuilder builder, Class classOfT) throws IOException, ApiException { + return invokeAndReturn(builder.toString(), classOfT); + } + + private T invokeAndReturn(String url, Class classOfT) throws IOException, ApiException { + JsonElement ele = GsonApiClient.invokeJson(url); return gson.fromJson(ele, classOfT); } diff --git a/src/main/java/eu/crushedpixel/replaymod/api/client/FileUploader.java b/src/main/java/eu/crushedpixel/replaymod/api/client/FileUploader.java index c6a8da4b..09806e6a 100644 --- a/src/main/java/eu/crushedpixel/replaymod/api/client/FileUploader.java +++ b/src/main/java/eu/crushedpixel/replaymod/api/client/FileUploader.java @@ -48,7 +48,7 @@ public class FileUploader { uploading = true; String postData = "?auth="+auth+"&category="+category.getId(); - + if(tags.size() > 0) { postData += "&tags="; for(String tag : tags) { @@ -58,7 +58,7 @@ public class FileUploader { } } } - + postData +="&name="+URLEncoder.encode(filename, "UTF-8"); System.out.println(postData); @@ -118,23 +118,28 @@ public class FileUploader { is = con.getErrorStream(); } - BufferedReader r = new BufferedReader(new InputStreamReader(is)); - String info = null; - if(responseCode != 200) { - ApiError error = new ApiError(-1, "An unknown error occured"); - String json = ""; - while(r.ready()) { - json += r.readLine(); + + if(is != null) { + BufferedReader r = new BufferedReader(new InputStreamReader(is)); + info = null; + if(responseCode != 200) { + ApiError error = new ApiError(-1, "An unknown error occured"); + String json = ""; + while(r.ready()) { + json += r.readLine(); + } + error = gson.fromJson(json, ApiError.class); + info = error.getDesc(); + System.out.println(info); } - System.out.println(json); - error = gson.fromJson(json, ApiError.class); - info = error.getDesc(); - System.out.println(info); } + con.disconnect(); + if(info == null) info = "An unknown error occured"; + parent.onFinishUploading(success, info); uploading = false; diff --git a/src/main/java/eu/crushedpixel/replaymod/api/client/QueryBuilder.java b/src/main/java/eu/crushedpixel/replaymod/api/client/QueryBuilder.java index 23393c8b..d87aa8e4 100644 --- a/src/main/java/eu/crushedpixel/replaymod/api/client/QueryBuilder.java +++ b/src/main/java/eu/crushedpixel/replaymod/api/client/QueryBuilder.java @@ -7,7 +7,7 @@ import java.util.Map; public class QueryBuilder { - private static final String API_BASE_URL = "http://ReplayMod.com/api/"; + public static final String API_BASE_URL = "http://ReplayMod.com/api/"; public String apiMethod; public Map paramMap; diff --git a/src/main/java/eu/crushedpixel/replaymod/api/client/holders/FileInfo.java b/src/main/java/eu/crushedpixel/replaymod/api/client/holders/FileInfo.java index 636e407e..a792bf9b 100644 --- a/src/main/java/eu/crushedpixel/replaymod/api/client/holders/FileInfo.java +++ b/src/main/java/eu/crushedpixel/replaymod/api/client/holders/FileInfo.java @@ -13,6 +13,21 @@ public class FileInfo { private int downloads; private String name; private boolean thumbnail; + + + public FileInfo(int id, ReplayMetaData metadata, String owner, + Rating ratings, int size, int category, int downloads, String name, + boolean thumbnail) { + this.id = id; + this.metadata = metadata; + this.owner = owner; + this.ratings = ratings; + this.size = size; + this.category = category; + this.downloads = downloads; + this.name = name; + this.thumbnail = thumbnail; + } public int getId() { return id; @@ -38,6 +53,9 @@ public class FileInfo { public String getName() { return name; } + public void setName(String name) { + this.name = name; + } public boolean hasThumbnail() { return thumbnail; } diff --git a/src/main/java/eu/crushedpixel/replaymod/entities/CameraEntity.java b/src/main/java/eu/crushedpixel/replaymod/entities/CameraEntity.java index 9906dd64..698fa25e 100644 --- a/src/main/java/eu/crushedpixel/replaymod/entities/CameraEntity.java +++ b/src/main/java/eu/crushedpixel/replaymod/entities/CameraEntity.java @@ -34,7 +34,8 @@ public class CameraEntity extends EntityPlayer { //frac = time since last tick public void updateMovement() { Minecraft mc = Minecraft.getMinecraft(); - if(ReplayHandler.getCameraEntity() != null && mc.thePlayer != null) { + if(ReplayHandler.getCameraEntity() != null && mc.thePlayer != null + && mc.getRenderViewEntity() != null) { //Aligns the particle rotation mc.thePlayer.rotationPitch = mc.getRenderViewEntity().rotationPitch; mc.thePlayer.rotationYaw = mc.getRenderViewEntity().rotationYaw; diff --git a/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java b/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java index 869b2647..b4b9bc4c 100644 --- a/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java @@ -13,6 +13,7 @@ import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiOptions; import net.minecraft.client.gui.GuiVideoSettings; import net.minecraft.client.gui.inventory.GuiInventory; +import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.resources.I18n; import net.minecraft.client.settings.GameSettings.Options; import net.minecraftforge.client.event.GuiOpenEvent; @@ -56,9 +57,9 @@ public class GuiEventHandler { event.gui = null; return; } - + if(!(event.gui instanceof GuiReplayManager || event.gui instanceof GuiUploadFile)) ResourceHelper.freeAllResources(); - + if(event.gui instanceof GuiMainMenu) { if(ReplayMod.firstMainMenu) { ReplayMod.firstMainMenu = false; @@ -162,20 +163,20 @@ public class GuiEventHandler { if(ReplayHandler.replayActive() && event.gui instanceof GuiIngameMenu && event.button.id == 1) { event.button.enabled = false; - Thread t = new Thread(new Runnable() { - @Override - public void run() { - ReplayHandler.endReplay(); + + mc.gameSettings.setOptionFloatValue(Options.GAMMA, ReplayHandler.getInitialGamma()); - mc.gameSettings.setOptionFloatValue(Options.GAMMA, ReplayHandler.getInitialGamma()); + ReplayHandler.lastExit = System.currentTimeMillis(); - ReplayHandler.lastExit = System.currentTimeMillis(); - mc.theWorld.sendQuittingDisconnectingPacket(); + /* This is already being executed by the default Exit action handling (vanilla code) + mc.theWorld.sendQuittingDisconnectingPacket(); + mc.loadWorld((WorldClient)null); + mc.displayGuiScreen(new GuiMainMenu()); + */ + + ReplayHandler.endReplay(); - ReplayGuiRegistry.show(); - } - }); - t.start(); + ReplayGuiRegistry.show(); } } diff --git a/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java b/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java index 8831f5fa..7bd6f75c 100644 --- a/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java @@ -90,7 +90,7 @@ public class GuiReplayOverlay extends Gui { private static boolean requestScreenshot = false; - private Field drawBlockOutline; + //private Field drawBlockOutline; public static void requestScreenshot() { requestScreenshot = true; @@ -98,13 +98,13 @@ public class GuiReplayOverlay extends Gui { public GuiReplayOverlay() { try { - drawBlockOutline = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175073_D")); - drawBlockOutline.setAccessible(true); - drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false); +// drawBlockOutline = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175073_D")); + // drawBlockOutline.setAccessible(true); + // drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false); } catch(Exception e) {} } - @SubscribeEvent + //@SubscribeEvent TODO public void renderHand(RenderHandEvent event) { if(ReplayHandler.replayActive()) { event.setCanceled(true); @@ -135,7 +135,8 @@ public class GuiReplayOverlay extends Gui { if(mc != null && mc.thePlayer != null) MinecraftTicker.runMouseKeyboardTick(mc); } - if(mc.getRenderViewEntity() == mc.thePlayer || !mc.getRenderViewEntity().isEntityAlive()) { + if(mc.getRenderViewEntity() == mc.thePlayer || !mc.getRenderViewEntity().isEntityAlive() + && ReplayHandler.getCameraEntity() != null) { ReplayHandler.spectateCamera(); ReplayHandler.getCameraEntity().movePath(new Position(lastX, lastY, lastZ, lastPitch, lastYaw)); } else if(!ReplayHandler.isCamera()) { @@ -169,6 +170,7 @@ public class GuiReplayOverlay extends Gui { @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent.Post event) throws IllegalArgumentException, IllegalAccessException { + if(!ReplayHandler.replayActive() || FMLClientHandler.instance().isGUIOpen(GuiSpectateSelection.class) || VideoWriter.isRecording()) { return; } @@ -185,7 +187,7 @@ public class GuiReplayOverlay extends Gui { } GL11.glEnable(GL11.GL_BLEND); - drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false); + // drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false); if(!ReplayHandler.replayActive()) { return; @@ -750,7 +752,7 @@ public class GuiReplayOverlay extends Gui { } private void addPlaceKeyframe() { - CameraEntity cam = ReplayHandler.getCameraEntity(); + Entity cam = mc.getRenderViewEntity(); if(cam == null) return; ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch, cam.rotationYaw))); } diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplayListEntry.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplayListEntry.java index df6fca7a..29d24d42 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplayListEntry.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplayListEntry.java @@ -2,7 +2,6 @@ package eu.crushedpixel.replaymod.gui; import java.awt.image.BufferedImage; import java.io.File; -import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -15,47 +14,31 @@ import javax.imageio.ImageIO; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiListExtended.IGuiListEntry; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.util.ResourceLocation; +import eu.crushedpixel.replaymod.api.client.holders.FileInfo; import eu.crushedpixel.replaymod.gui.replaymanager.ResourceHelper; -import eu.crushedpixel.replaymod.recording.ReplayMetaData; public class GuiReplayListEntry implements IGuiListEntry { private Minecraft minecraft = Minecraft.getMinecraft(); private final DateFormat dateFormat = new SimpleDateFormat(); - private ReplayMetaData metaData; - private String fileName; - + private FileInfo fileInfo; + private ResourceLocation textureResource; private DynamicTexture dynTex = null; private File imageFile; private BufferedImage image = null; - - public ReplayMetaData getMetaData() { - return metaData; - } - - public void setMetaData(ReplayMetaData metaData) { - this.metaData = metaData; - } - - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - private GuiReplayListExtended parent; + + public FileInfo getFileInfo() { + return fileInfo; + } - public GuiReplayListEntry(GuiReplayListExtended parent, String fileName, ReplayMetaData metaData, File imageFile) { - this.metaData = metaData; - this.fileName = fileName; + public GuiReplayListEntry(GuiReplayListExtended parent, FileInfo fileInfo, File imageFile) { + this.fileInfo = fileInfo; this.parent = parent; dynTex = null; this.imageFile = imageFile; @@ -66,7 +49,10 @@ public class GuiReplayListEntry implements IGuiListEntry { @Override public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) { try { - minecraft.fontRendererObj.drawString(fileName, x + 3, y + 1, 16777215); + if(fileInfo.getName() == null || fileInfo.getName().length() < 1) { + fileInfo.setName("No Name"); + } + minecraft.fontRendererObj.drawString(fileInfo.getName(), x + 3, y + 1, 16777215); if(y < -slotHeight || y > parent.height) { if(registered) { @@ -79,7 +65,7 @@ public class GuiReplayListEntry implements IGuiListEntry { return; } else { if(!registered) { - textureResource = new ResourceLocation("thumbs/"+fileName); + textureResource = new ResourceLocation("thumbs/"+fileInfo.getName()+fileInfo.getId()); if(imageFile == null) { image = ResourceHelper.getDefaultThumbnail(); } else { @@ -97,12 +83,12 @@ public class GuiReplayListEntry implements IGuiListEntry { } List list = new ArrayList(); - list.add(metaData.getServerName()+" ("+dateFormat.format(new Date(metaData.getDate()))+")"); + list.add(fileInfo.getMetadata().getServerName()+" ("+dateFormat.format(new Date(fileInfo.getMetadata().getDate()))+")"); list.add(String.format("%02dm%02ds", - TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()), - TimeUnit.MILLISECONDS.toSeconds(metaData.getDuration()) - - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration())) + TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()), + TimeUnit.MILLISECONDS.toSeconds(fileInfo.getMetadata().getDuration()) - + TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration())) )); for (int l1 = 0; l1 < Math.min(list.size(), 2); ++l1) { diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplayListExtended.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplayListExtended.java index 6d0540c3..b71af102 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplayListExtended.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplayListExtended.java @@ -13,7 +13,7 @@ import net.minecraft.util.MathHelper; import org.lwjgl.input.Mouse; -import eu.crushedpixel.replaymod.recording.ReplayMetaData; +import eu.crushedpixel.replaymod.api.client.holders.FileInfo; public abstract class GuiReplayListExtended extends GuiListExtended { @@ -81,8 +81,8 @@ public abstract class GuiReplayListExtended extends GuiListExtended { entries = new ArrayList(); } - public void addEntry(String fileName, ReplayMetaData metaData, File image) { - entries.add(new GuiReplayListEntry(this, fileName, metaData, image)); + public void addEntry(FileInfo fileInfo, File image) { + entries.add(new GuiReplayListEntry(this, fileInfo, image)); } @Override diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiSpectateSelection.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiSpectateSelection.java index 3cc78735..a0cbc390 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiSpectateSelection.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiSpectateSelection.java @@ -3,6 +3,7 @@ package eu.crushedpixel.replaymod.gui; import java.awt.Color; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -14,7 +15,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EnumPlayerModelParts; import net.minecraft.potion.Potion; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.common.versioning.ComparableVersion; import com.mojang.realmsclient.util.Pair; @@ -53,7 +53,7 @@ public class GuiSpectateSelection extends GuiScreen { public GuiSpectateSelection(List players) { this.prevSpeed = ReplayHandler.getSpeed(); - players.sort(new PlayerComparator()); + Collections.sort(players, new PlayerComparator()); this.players = new ArrayList>(); diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java b/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java index ed0ce425..c560e516 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java @@ -17,6 +17,8 @@ import org.lwjgl.input.Keyboard; import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.api.client.ApiException; +import eu.crushedpixel.replaymod.api.client.SearchPagination; +import eu.crushedpixel.replaymod.api.client.SearchQuery; import eu.crushedpixel.replaymod.api.client.holders.FileInfo; import eu.crushedpixel.replaymod.gui.GuiConstants; import eu.crushedpixel.replaymod.gui.GuiReplayListExtended; @@ -35,12 +37,25 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { private Tab currentTab = Tab.RECENT_FILES; + private static final SearchQuery recentFileSearchQuery = new SearchQuery(false, null, null, null, null, null, + null, null, null, null); + + private static final SearchQuery bestFileSearchQuery = new SearchQuery(true, null, null, null, null, null, + null, null, null, null); + + private final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery); + private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery); + private SearchPagination myFilePagination; + @Override public void initGui() { Keyboard.enableRepeatEvents(true); - if(!AuthenticationHandler.isAuthenticated()) { - mc.displayGuiScreen(new GuiLoginPrompt(new GuiMainMenu(), this)); - return; + + if(AuthenticationHandler.isAuthenticated()) { + SearchQuery query = new SearchQuery(); + query.auth = AuthenticationHandler.getKey(); + query.order = false; + myFilePagination = new SearchPagination(query); } //Top Button Bar @@ -53,6 +68,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { buttonBar.add(bestButton); GuiButton ownReplayButton = new GuiButton(GuiConstants.CENTER_MY_REPLAYS_BUTTON, 20, 30, "My Replays"); + ownReplayButton.enabled = AuthenticationHandler.isAuthenticated(); buttonBar.add(ownReplayButton); GuiButton searchButton = new GuiButton(GuiConstants.CENTER_SEARCH_BUTTON, 20, 30, "Search"); @@ -115,9 +131,9 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { } else if(button.id == GuiConstants.CENTER_RECENT_BUTTON) { showOnlineRecent(); } else if(button.id == GuiConstants.CENTER_BEST_BUTTON) { - + showOnlineBest(); } else if(button.id == GuiConstants.CENTER_MY_REPLAYS_BUTTON) { - + showOnlineOwnFiles(); } else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) { } @@ -188,40 +204,67 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { Keyboard.enableRepeatEvents(false); } + private void updateCurrentList(ReplayFileList list, SearchPagination pagination) { + currentList = list; + if(currentList == null) { + currentList = new ReplayFileList(mc, width, height, 50, height-40, 36); + } else { + currentList.clearEntries(); + currentList.width = width; + currentList.height = height; + currentList.top = 50; + currentList.bottom = height-40; + } + + if(pagination.getLoadedPages() < 0) { + pagination.fetchPage(); + } + + for(FileInfo i : pagination.getFiles()) { + try { + File tmp = null; + if(i.hasThumbnail()) { + tmp = File.createTempFile("thumb_online_"+i.getId(), "jpg"); + ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp); + } + currentList.addEntry(i, tmp); + } catch(Exception e) { + e.printStackTrace(); + } + } + } + public void showOnlineRecent() { Thread t = new Thread(new Runnable() { @Override public void run() { - try { - if(recentFileList == null) { - recentFileList = new ReplayFileList(mc, width, height, 50, height-40, 36); - } else { - recentFileList.clearEntries(); - recentFileList.width = width; - recentFileList.height = height; - recentFileList.top = 50; - recentFileList.bottom = height-40; - } - currentTab = Tab.RECENT_FILES; - currentList = recentFileList; - FileInfo[] files = ReplayMod.apiClient.getRecentFiles(); - for(FileInfo i : files) { - File tmp = null; - if(i.hasThumbnail()) { - tmp = File.createTempFile("thumb_online_"+i.getId(), "jpg"); - ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp); - } - recentFileList.addEntry(i.getName(), i.getMetadata(), tmp); - } - } catch (IOException e) { - e.printStackTrace(); - } catch (ApiException e) { //TODO: Error message - e.printStackTrace(); - } + updateCurrentList(recentFileList, recentFilePagination); + currentTab = Tab.RECENT_FILES; } }); t.start(); + } + public void showOnlineBest() { + Thread t = new Thread(new Runnable() { + @Override + public void run() { + updateCurrentList(bestFileList, bestFilePagination); + currentTab = Tab.BEST_FILES; + } + }); + t.start(); + } + public void showOnlineOwnFiles() { + if(!AuthenticationHandler.isAuthenticated() || myFilePagination == null) return; + Thread t = new Thread(new Runnable() { + @Override + public void run() { + updateCurrentList(myFileList, myFilePagination); + currentTab = Tab.MY_FILES; + } + }); + t.start(); } } diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/replaymanager/GuiReplayManager.java b/src/main/java/eu/crushedpixel/replaymod/gui/replaymanager/GuiReplayManager.java index 541ee5c6..eb76ecbf 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/replaymanager/GuiReplayManager.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/replaymanager/GuiReplayManager.java @@ -37,6 +37,7 @@ import org.lwjgl.input.Keyboard; import com.google.gson.Gson; import com.mojang.realmsclient.util.Pair; +import eu.crushedpixel.replaymod.api.client.holders.FileInfo; import eu.crushedpixel.replaymod.gui.GuiReplayListExtended; import eu.crushedpixel.replaymod.gui.GuiReplaySettings; import eu.crushedpixel.replaymod.gui.online.GuiUploadFile; @@ -122,7 +123,9 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback { Collections.sort(replayFileList, new FileAgeComparator()); for(Pair, File> p : replayFileList) { - replayGuiList.addEntry(FilenameUtils.getBaseName(p.first().first().getName()), p.first().second(), p.second()); + FileInfo fileInfo = new FileInfo(-1, p.first().second(), null, null, + -1, -1, -1, FilenameUtils.getBaseName(p.first().first().getName()), true); + replayGuiList.addEntry(fileInfo, p.second()); } } @@ -204,7 +207,7 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback { mc.displayGuiScreen(parentScreen); } else if(button.id == DELETE_BUTTON_ID) { - String s = replayGuiList.getListEntry(replayGuiList.selected).getFileName(); + String s = replayGuiList.getListEntry(replayGuiList.selected).getFileInfo().getName(); if (s != null) { delete_file = true; diff --git a/src/main/java/eu/crushedpixel/replaymod/registry/ReplayGuiRegistry.java b/src/main/java/eu/crushedpixel/replaymod/registry/ReplayGuiRegistry.java index 168985df..67bddbcc 100644 --- a/src/main/java/eu/crushedpixel/replaymod/registry/ReplayGuiRegistry.java +++ b/src/main/java/eu/crushedpixel/replaymod/registry/ReplayGuiRegistry.java @@ -4,24 +4,27 @@ import java.lang.reflect.Field; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.network.play.server.S0CPacketSpawnPlayer; import net.minecraftforge.client.GuiIngameForge; import eu.crushedpixel.replaymod.reflection.MCPNames; public class ReplayGuiRegistry { - private static Field renderHand; + //private static Field renderHand; private static Minecraft mc = Minecraft.getMinecraft(); public static boolean hidden = false; + /* static { try { - renderHand = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175074_C")); - renderHand.setAccessible(true); + //renderHand = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175074_C")); + //renderHand.setAccessible(true); } catch(Exception e) { e.printStackTrace(); } } + */ public static void hide() { if(hidden) return; @@ -39,11 +42,13 @@ public class ReplayGuiRegistry { GuiIngameForge.renderJumpBar = false; GuiIngameForge.renderObjective = false; + /* try { renderHand.set(mc.entityRenderer, false); } catch(Exception e) { e.printStackTrace(); } + */ hidden = true; } @@ -65,11 +70,13 @@ public class ReplayGuiRegistry { GuiIngameForge.renderJumpBar = true; GuiIngameForge.renderObjective = true; + /* try { renderHand.set(mc.entityRenderer, true); } catch(Exception e) { e.printStackTrace(); } + */ hidden = false; } diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/MCTimerHandler.java b/src/main/java/eu/crushedpixel/replaymod/replay/MCTimerHandler.java index e1507f3c..887d9e09 100644 --- a/src/main/java/eu/crushedpixel/replaymod/replay/MCTimerHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/MCTimerHandler.java @@ -39,7 +39,6 @@ public class MCTimerHandler { try { if(!(getTimer() instanceof ReplayTimer)) { timerBefore = getTimer(); - System.out.println("here"); mcTimer.set(mc, rpt); } } catch(Exception e) { @@ -152,12 +151,12 @@ public class MCTimerHandler { } return 1; } - + public static void updateTimer(double d) { - try{ + try { Timer t = getTimer(); double d2 = d; - d2 = MathHelper.clamp_double(d2, 0.0D, 1.0D); + //d2 = MathHelper.clamp_double(d2, 0.0D, 1.0D); t.elapsedPartialTicks = (float)((double)t.elapsedPartialTicks + d2 * (double)t.timerSpeed * 20); t.elapsedTicks = (int)t.elapsedPartialTicks; t.elapsedPartialTicks -= (float)t.elapsedTicks; diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java index 77194cda..c5dee480 100644 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java @@ -361,6 +361,9 @@ public class ReplayHandler { ReplayMod.overlay.resetUI(); } catch(Exception e) {} + //Load lighting and trigger update + ReplayMod.replaySettings.setLightingEnabled(ReplayMod.replaySettings.isLightingEnabled()); + replayActive = true; } @@ -397,9 +400,11 @@ public class ReplayHandler { resetKeyframes(); - if(channel != null) { + /* + if(channel != null && channel.isOpen()) { channel.close(); } + */ replayActive = false; } diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java index 98880848..f1f5784a 100644 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java @@ -330,7 +330,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { dis = new DataInputStream(archive.getInputStream(replayEntry)); setReplaySpeed(0); } catch(IOException e) { - e.printStackTrace(); + //e.printStackTrace(); } } } @@ -442,6 +442,8 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { difficulty, maxPlayers, worldType, false); } + /* + * Proof of concept for some nasty player manipulation ;) String crPxl = "2cb08a5951f34e98bd0985d9747e80df"; String johni = "cd3d4be14ffc2f9db432db09e0cd254b"; @@ -469,6 +471,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { p = sp; } + */ if(p instanceof S07PacketRespawn) { allowMovement = true; diff --git a/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java b/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java index 1a990fed..1e6e530a 100644 --- a/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java +++ b/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java @@ -5,7 +5,10 @@ import java.util.LinkedHashMap; import java.util.Map; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiOptions; +import net.minecraft.client.gui.GuiVideoSettings; import net.minecraft.client.settings.GameSettings.Options; +import net.minecraft.entity.player.EnumPlayerModelParts; import net.minecraft.util.Timer; import net.minecraftforge.common.config.Property; import eu.crushedpixel.replaymod.ReplayMod; @@ -90,6 +93,7 @@ public class ReplaySettings { public boolean isLightingEnabled() { return lightingEnabled; } + public void setLightingEnabled(boolean enabled) { this.lightingEnabled = enabled; if(enabled) {