Fix all warnings

Add and make use of Lombok
Remove Mojang API
Remove ZipFileUtils
Remove StreamTools in favor of Apache IOUtils
Keyframe should be abstract all derivatives final
Replace clone in Keyframe with copy
Move some constants from GuiReplaySetttings to GuiConstants
This commit is contained in:
johni0702
2015-06-29 21:45:37 +02:00
parent 3122c0a71e
commit a058497727
110 changed files with 487 additions and 1921 deletions

View File

@@ -11,7 +11,6 @@ import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
public class FileUploader {
@@ -21,14 +20,8 @@ public class FileUploader {
private long filesize;
private long current;
private String attachmentName = "file";
private String attachmentFileName = "file.mcpr";
private String crlf = "\r\n";
private String twoHyphens = "--";
private boolean cancel = false;
private String boundary = "*****";
private GuiUploadFile parent;
public void uploadFile(GuiUploadFile gui, String auth, String filename, List<String> tags, File file, Category category, String description)
@@ -62,7 +55,7 @@ public class FileUploader {
postData += "&name=" + URLEncoder.encode(filename, "UTF-8");
String url = "http://ReplayMod.com/api/upload_file" + postData;
String url = ReplayModApiMethods.upload_file + postData;
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setUseCaches(false);
con.setDoOutput(true);
@@ -70,18 +63,18 @@ public class FileUploader {
con.setChunkedStreamingMode(1024);
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Cache-Control", "no-cache");
con.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + this.boundary);
HashMap<String, String> params = new HashMap<String, String>();
params.put("auth", auth);
params.put("name", filename);
params.put("category", category.getId() + "");
String boundary = "*****";
con.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
DataOutputStream request = new DataOutputStream(con.getOutputStream());
request.writeBytes(this.twoHyphens + this.boundary + this.crlf);
request.writeBytes("Content-Disposition: form-data; name=\"" + this.attachmentName + "\";filename=\"" + this.attachmentFileName + "\"" + this.crlf);
request.writeBytes(this.crlf);
String crlf = "\r\n";
String twoHyphens = "--";
request.writeBytes(twoHyphens + boundary + crlf);
String attachmentName = "file";
String attachmentFileName = "file.mcpr";
request.writeBytes("Content-Disposition: form-data; name=\"" + attachmentName + "\";filename=\"" + attachmentFileName + "\"" + crlf);
request.writeBytes(crlf);
byte[] buf = new byte[1024];
FileInputStream fis = new FileInputStream(file);
@@ -102,8 +95,8 @@ public class FileUploader {
}
fis.close();
request.writeBytes(this.crlf);
request.writeBytes(this.twoHyphens + this.boundary + this.twoHyphens + this.crlf);
request.writeBytes(crlf);
request.writeBytes(twoHyphens + boundary + twoHyphens + crlf);
request.flush();
request.close();

View File

@@ -1,32 +1,17 @@
package eu.crushedpixel.replaymod.api.replay;
import lombok.AllArgsConstructor;
import java.lang.reflect.Field;
import java.net.URLEncoder;
@AllArgsConstructor
public class SearchQuery {
public Boolean order, singleplayer;
public String player, tag, version, server, name, auth;
public Integer category, offset;
public SearchQuery() {
}
public SearchQuery(Boolean order, Boolean singleplayer, String player,
String tag, String version, String server, String name,
String auth, Integer category, Integer offset) {
this.order = order;
this.singleplayer = singleplayer;
this.player = player;
this.tag = tag;
this.version = version;
this.server = server;
this.name = name;
this.auth = auth;
this.category = category;
this.offset = offset;
}
public String buildQuery() {
String query = "";
boolean first = true;

View File

@@ -1,7 +1,9 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import lombok.Data;
import net.minecraft.client.resources.I18n;
@Data
public class ApiError {
private int id;
@@ -9,27 +11,6 @@ public class ApiError {
private String key;
private String[] objects;
public ApiError(int id, String desc) {
this.id = id;
this.desc = desc;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getTranslatedDesc() {
try {
return I18n.format(key, (Object[]) objects);

View File

@@ -1,10 +1,9 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import lombok.Data;
@Data
public class AuthConfirmation {
private String username;
private int id;
public String getUsername() {
return username;
}
}

View File

@@ -1,14 +1,12 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AuthKey {
private String auth;
public AuthKey(String authkey) {
this.auth = authkey;
}
public String getAuthkey() {
return auth;
}
}

View File

@@ -1,7 +1,13 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
@Data
public class Donated {
@Getter(AccessLevel.NONE)
private boolean donated = false;
public boolean hasDonated() {

View File

@@ -1,7 +1,8 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import lombok.Data;
@Data
public class Favorites {
private int[] favorited;
public int[] getFavorited() { return favorited; }
}

View File

@@ -1,9 +1,14 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
@Data
@AllArgsConstructor
public class FileInfo {
private int id;
private ReplayMetaData metadata;
private String owner;
@@ -11,67 +16,12 @@ public class FileInfo {
private int size;
private int category;
private int downloads;
private int favorites;
private String name;
@Getter(AccessLevel.NONE)
private boolean thumbnail;
public FileInfo(int id, ReplayMetaData metadata, String owner,
Rating ratings, int size, int category, int downloads, String name,
boolean thumbnail, int favorites) {
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;
this.favorites = favorites;
}
public int getId() {
return id;
}
public ReplayMetaData getMetadata() {
return metadata;
}
public String getOwner() {
return owner;
}
public Rating getRatings() {
return ratings;
}
public int getSize() {
return size;
}
public int getCategory() {
return category;
}
public int getDownloads() {
return downloads;
}
public int getFavorites() { return favorites; }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private int favorites;
public boolean hasThumbnail() {
return thumbnail;
}
}

View File

@@ -1,5 +1,8 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import lombok.Data;
@Data
public class FileRating {
private int file;
@@ -9,6 +12,7 @@ public class FileRating {
return file;
}
// TODO Will be changed later
public boolean getRating() {
return rating;
}

View File

@@ -1,10 +1,8 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import lombok.Data;
@Data
public class RatedFiles {
private FileRating[] rated;
public FileRating[] getRated() {
return rated;
}
}

View File

@@ -1,17 +1,11 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import lombok.Data;
@Data
public class Rating {
private int negative, positive;
public int getNegative() {
return negative;
}
public int getPositive() {
return positive;
}
public enum RatingType {
LIKE("like"), DISLIKE("dislike"), NEUTRAL("neutral");

View File

@@ -1,10 +1,8 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import lombok.Data;
@Data
public class SearchResult {
private FileInfo[] results;
public FileInfo[] getResults() {
return results;
}
}

View File

@@ -1,10 +1,8 @@
package eu.crushedpixel.replaymod.api.replay.holders;
import lombok.Data;
@Data
public class Success {
private boolean success = false;
public boolean isSuccess() {
return success;
}
}

View File

@@ -1,22 +1,10 @@
package eu.crushedpixel.replaymod.api.replay.holders;
public class UserFiles {
import lombok.Data;
@Data
public class UserFiles {
private String user;
private FileInfo[] files;
private int total_size;
public String getUser() {
return user;
}
public FileInfo[] getFiles() {
return files;
}
public int getTotal_size() {
return total_size;
}
}

View File

@@ -5,11 +5,11 @@ import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
import java.util.List;
public interface Pagination {
public List<FileInfo> getFiles();
List<FileInfo> getFiles();
public int getLoadedPages();
int getLoadedPages();
public boolean fetchPage();
boolean fetchPage();
public static final int PAGE_SIZE = 30; //defined by the Website API
int PAGE_SIZE = 30; //defined by the Website API
}