Fixed Upload GUI, added Tag Input
This commit is contained in:
@@ -102,5 +102,9 @@ public class ReplayMod
|
|||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(AuthenticationHandler.isBlacklisted(Minecraft.getMinecraft().getSession().getPlayerID())) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
@@ -37,7 +39,7 @@ public class FileUploader {
|
|||||||
private GuiUploadFile parent;
|
private GuiUploadFile parent;
|
||||||
//private CountingHttpEntity counter;
|
//private CountingHttpEntity counter;
|
||||||
|
|
||||||
public void uploadFile(GuiUploadFile gui, String auth, String filename, File file, Category category) throws IOException, ApiException, RuntimeException {
|
public void uploadFile(GuiUploadFile gui, String auth, String filename, List<String> tags, File file, Category category) throws IOException, ApiException, RuntimeException {
|
||||||
parent = gui;
|
parent = gui;
|
||||||
gui.onStartUploading();
|
gui.onStartUploading();
|
||||||
filesize = 0;
|
filesize = 0;
|
||||||
@@ -45,7 +47,20 @@ public class FileUploader {
|
|||||||
if(uploading) throw new RuntimeException("FileUploader is already uploading");
|
if(uploading) throw new RuntimeException("FileUploader is already uploading");
|
||||||
uploading = true;
|
uploading = true;
|
||||||
|
|
||||||
String postData = "?auth="+auth+"&category="+category.getId()+"&name="+filename;
|
String postData = "?auth="+auth+"&category="+category.getId();
|
||||||
|
|
||||||
|
if(tags.size() > 0) {
|
||||||
|
postData += "&tags=";
|
||||||
|
for(String tag : tags) {
|
||||||
|
postData += tag;
|
||||||
|
if(!tag.equals(tags.get(tags.size()-1))) {
|
||||||
|
postData += ",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
postData +="&name="+URLEncoder.encode(filename, "UTF-8");
|
||||||
|
System.out.println(postData);
|
||||||
|
|
||||||
String url = "http://ReplayMod.com/api/upload_file"+postData;
|
String url = "http://ReplayMod.com/api/upload_file"+postData;
|
||||||
HttpURLConnection con = (HttpURLConnection)new URL(url).openConnection();
|
HttpURLConnection con = (HttpURLConnection)new URL(url).openConnection();
|
||||||
@@ -108,10 +123,14 @@ public class FileUploader {
|
|||||||
String info = null;
|
String info = null;
|
||||||
if(responseCode != 200) {
|
if(responseCode != 200) {
|
||||||
ApiError error = new ApiError(-1, "An unknown error occured");
|
ApiError error = new ApiError(-1, "An unknown error occured");
|
||||||
|
String json = "";
|
||||||
while(r.ready()) {
|
while(r.ready()) {
|
||||||
error = gson.fromJson(r.readLine(), ApiError.class);
|
json += r.readLine();
|
||||||
}
|
}
|
||||||
|
System.out.println(json);
|
||||||
|
error = gson.fromJson(json, ApiError.class);
|
||||||
info = error.getDesc();
|
info = error.getDesc();
|
||||||
|
System.out.println(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
con.disconnect();
|
con.disconnect();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import net.minecraft.client.gui.GuiVideoSettings;
|
|||||||
import net.minecraft.client.gui.inventory.GuiInventory;
|
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.client.settings.GameSettings.Options;
|
import net.minecraft.client.settings.GameSettings.Options;
|
||||||
|
import net.minecraft.util.Timer;
|
||||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||||
import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent;
|
import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent;
|
||||||
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent;
|
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent;
|
||||||
@@ -32,6 +33,7 @@ import eu.crushedpixel.replaymod.gui.replaymanager.ResourceHelper;
|
|||||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||||
import eu.crushedpixel.replaymod.registry.ReplayGuiRegistry;
|
import eu.crushedpixel.replaymod.registry.ReplayGuiRegistry;
|
||||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||||
|
import eu.crushedpixel.replaymod.replay.ReplaySender;
|
||||||
|
|
||||||
public class GuiEventHandler {
|
public class GuiEventHandler {
|
||||||
|
|
||||||
@@ -55,7 +57,12 @@ public class GuiEventHandler {
|
|||||||
event.gui = new GuiLoginPrompt(event.gui, event.gui);
|
event.gui = new GuiLoginPrompt(event.gui, event.gui);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
ReplayHandler.setSpeed(1f);
|
try {
|
||||||
|
Timer timer = (Timer)ReplaySender.mcTimer.get(mc);
|
||||||
|
timer.timerSpeed = 1f;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +132,8 @@ public class GuiEventHandler {
|
|||||||
rc.enabled = true;
|
rc.enabled = true;
|
||||||
event.buttonList.add(rc);
|
event.buttonList.add(rc);
|
||||||
} else if(event.gui instanceof GuiOptions) {
|
} else if(event.gui instanceof GuiOptions) {
|
||||||
event.buttonList.add(new GuiButton(9001, event.gui.width / 2 - 155, event.gui.height / 6 + 48 - 6 - 24, 310, 20, "Replay Mod Settings..."));
|
event.buttonList.add(new GuiButton(GuiConstants.REPLAY_OPTIONS_BUTTON_ID,
|
||||||
|
event.gui.width / 2 - 155, event.gui.height / 6 + 48 - 6 - 24, 310, 20, "Replay Mod Settings..."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +169,7 @@ public class GuiEventHandler {
|
|||||||
ReplayGuiRegistry.show();
|
ReplayGuiRegistry.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
t.run();
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class GuiConstants {
|
|||||||
public static final int UPLOAD_BACK_BUTTON = 3005;
|
public static final int UPLOAD_BACK_BUTTON = 3005;
|
||||||
public static final int UPLOAD_INFO_FIELD = 3006;
|
public static final int UPLOAD_INFO_FIELD = 3006;
|
||||||
public static final int UPLOAD_TAG_INPUT = 3007;
|
public static final int UPLOAD_TAG_INPUT = 3007;
|
||||||
|
public static final int UPLOAD_TAG_PLACEHOLDER = 3008;
|
||||||
|
|
||||||
public static final int REPLAY_OPTIONS_BUTTON_ID = 8000;
|
public static final int REPLAY_OPTIONS_BUTTON_ID = 8000;
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ public class GuiReplaySettings extends GuiScreen {
|
|||||||
int k = 0;
|
int k = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Entry<String, Object> e : aoptions.entrySet()) {
|
for (Entry<String, Object> e : aoptions.entrySet()) {
|
||||||
|
|
||||||
|
/*
|
||||||
if(e.getKey().equals("Maximum File Size")) {
|
if(e.getKey().equals("Maximum File Size")) {
|
||||||
float minValue = -1;
|
float minValue = -1;
|
||||||
float maxValue = 10000;
|
float maxValue = 10000;
|
||||||
@@ -54,7 +56,9 @@ public class GuiReplaySettings extends GuiScreen {
|
|||||||
int val = (Integer)e.getValue();
|
int val = (Integer)e.getValue();
|
||||||
this.buttonList.add(new GuiSizeLimitOptionSlider(MAXSIZE_SLIDER_ID, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 0, 39, 1, val, e.getKey()));
|
this.buttonList.add(new GuiSizeLimitOptionSlider(MAXSIZE_SLIDER_ID, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 0, 39, 1, val, e.getKey()));
|
||||||
|
|
||||||
} else if(e.getKey().equals("Enable Notifications")) {
|
} else
|
||||||
|
*/
|
||||||
|
if(e.getKey().equals("Enable Notifications")) {
|
||||||
sendChatButton = new GuiButton(SEND_CHAT, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Enable Notifications: "+onOff((Boolean)e.getValue()));
|
sendChatButton = new GuiButton(SEND_CHAT, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Enable Notifications: "+onOff((Boolean)e.getValue()));
|
||||||
this.buttonList.add(sendChatButton);
|
this.buttonList.add(sendChatButton);
|
||||||
} else if(e.getKey().equals("Record Server")) {
|
} else if(e.getKey().equals("Record Server")) {
|
||||||
@@ -90,8 +94,7 @@ public class GuiReplaySettings extends GuiScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||||
{
|
|
||||||
this.drawDefaultBackground();
|
this.drawDefaultBackground();
|
||||||
this.drawCenteredString(this.fontRendererObj, "Replay Mod Settings", this.width / 2, 20, 16777215);
|
this.drawCenteredString(this.fontRendererObj, "Replay Mod Settings", this.width / 2, 20, 16777215);
|
||||||
if (FMLClientHandler.instance().getClient().thePlayer != null) {
|
if (FMLClientHandler.instance().getClient().thePlayer != null) {
|
||||||
@@ -102,10 +105,8 @@ public class GuiReplaySettings extends GuiScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void actionPerformed(GuiButton button) throws IOException
|
protected void actionPerformed(GuiButton button) throws IOException {
|
||||||
{
|
if (button.enabled) {
|
||||||
if (button.enabled)
|
|
||||||
{
|
|
||||||
switch(button.id) {
|
switch(button.id) {
|
||||||
case 200:
|
case 200:
|
||||||
this.mc.displayGuiScreen(this.parentGuiScreen);
|
this.mc.displayGuiScreen(this.parentGuiScreen);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import eu.crushedpixel.replaymod.utils.ImageUtils;
|
|||||||
|
|
||||||
public class GuiUploadFile extends GuiScreen {
|
public class GuiUploadFile extends GuiScreen {
|
||||||
|
|
||||||
private GuiTextField fileTitleInput, tagInput, messageTextField;
|
private GuiTextField fileTitleInput, tagInput, messageTextField, tagPlaceholder;
|
||||||
private GuiButton categoryButton, startUploadButton, cancelUploadButton, backButton;
|
private GuiButton categoryButton, startUploadButton, cancelUploadButton, backButton;
|
||||||
|
|
||||||
private Gson gson = new Gson();
|
private Gson gson = new Gson();
|
||||||
@@ -62,6 +62,9 @@ public class GuiUploadFile extends GuiScreen {
|
|||||||
|
|
||||||
private Minecraft mc = Minecraft.getMinecraft();
|
private Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
|
private static final Pattern p = Pattern.compile("[^a-z0-9 \\-_]", Pattern.CASE_INSENSITIVE);
|
||||||
|
private static final Pattern pt = Pattern.compile("[^a-z0-9,]", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
public GuiUploadFile(File file) {
|
public GuiUploadFile(File file) {
|
||||||
this.textureResource = new ResourceLocation("upload_thumbs/"+FilenameUtils.getBaseName(file.getAbsolutePath()));
|
this.textureResource = new ResourceLocation("upload_thumbs/"+FilenameUtils.getBaseName(file.getAbsolutePath()));
|
||||||
dynTex = null;
|
dynTex = null;
|
||||||
@@ -127,14 +130,27 @@ public class GuiUploadFile extends GuiScreen {
|
|||||||
public void initGui() {
|
public void initGui() {
|
||||||
if(replayFile == null) return;
|
if(replayFile == null) return;
|
||||||
|
|
||||||
|
if(fileTitleInput == null) {
|
||||||
fileTitleInput = new GuiTextField(GuiConstants.UPLOAD_NAME_INPUT, fontRendererObj, (this.width/2)+20+10, 21, Math.min(200, this.width-20-260), 20);
|
fileTitleInput = new GuiTextField(GuiConstants.UPLOAD_NAME_INPUT, fontRendererObj, (this.width/2)+20+10, 21, Math.min(200, this.width-20-260), 20);
|
||||||
String fname = FilenameUtils.getBaseName(replayFile.getAbsolutePath());
|
String fname = FilenameUtils.getBaseName(replayFile.getAbsolutePath());
|
||||||
fileTitleInput.setText(fname);
|
fileTitleInput.setText(fname);
|
||||||
|
fileTitleInput.setMaxStringLength(30);
|
||||||
|
} else {
|
||||||
|
fileTitleInput.xPosition = (this.width/2)+20+10;
|
||||||
|
//fileTitleInput.yPosition = 21;
|
||||||
|
fileTitleInput.width = Math.min(200, this.width-20-260);
|
||||||
|
//fileTitleInput.height = 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(categoryButton == null) {
|
||||||
categoryButton = new GuiButton(GuiConstants.UPLOAD_CATEGORY_BUTTON, (this.width/2)+20+10-1, 80, "Category: "+category.toNiceString());
|
categoryButton = new GuiButton(GuiConstants.UPLOAD_CATEGORY_BUTTON, (this.width/2)+20+10-1, 80, "Category: "+category.toNiceString());
|
||||||
categoryButton.width = Math.min(202, this.width-20-260+2);
|
categoryButton.width = Math.min(202, this.width-20-260+2);
|
||||||
buttonList.add(categoryButton);
|
buttonList.add(categoryButton);
|
||||||
|
} else {
|
||||||
|
categoryButton.xPosition = (this.width/2)+20+10-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(startUploadButton == null) {
|
||||||
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
|
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
|
||||||
startUploadButton = new GuiButton(GuiConstants.UPLOAD_START_BUTTON, 0, 0, "Start Upload");
|
startUploadButton = new GuiButton(GuiConstants.UPLOAD_START_BUTTON, 0, 0, "Start Upload");
|
||||||
bottomBar.add(startUploadButton);
|
bottomBar.add(startUploadButton);
|
||||||
@@ -146,12 +162,6 @@ public class GuiUploadFile extends GuiScreen {
|
|||||||
backButton = new GuiButton(GuiConstants.UPLOAD_BACK_BUTTON, 0, 0, "Back");
|
backButton = new GuiButton(GuiConstants.UPLOAD_BACK_BUTTON, 0, 0, "Back");
|
||||||
bottomBar.add(backButton);
|
bottomBar.add(backButton);
|
||||||
|
|
||||||
messageTextField = new GuiTextField(GuiConstants.UPLOAD_INFO_FIELD, fontRendererObj, 20, height-80, width-40, 20);
|
|
||||||
messageTextField.setEnabled(true);
|
|
||||||
messageTextField.setFocused(false);
|
|
||||||
|
|
||||||
tagInput = new GuiTextField(GuiConstants.UPLOAD_TAG_INPUT, fontRendererObj, (this.width/2)+20+10, 110, Math.min(200, this.width-20-260), 20);
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(GuiButton b : bottomBar) {
|
for(GuiButton b : bottomBar) {
|
||||||
int w = this.width - 30;
|
int w = this.width - 30;
|
||||||
@@ -166,9 +176,57 @@ public class GuiUploadFile extends GuiScreen {
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
|
||||||
|
|
||||||
startUploadButton.enabled = (!(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30 ||
|
bottomBar.add(startUploadButton);
|
||||||
p.matcher(fileTitleInput.getText()).find()));
|
bottomBar.add(cancelUploadButton);
|
||||||
|
bottomBar.add(backButton);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for(GuiButton b : bottomBar) {
|
||||||
|
int w = this.width - 30;
|
||||||
|
int w2 = w/bottomBar.size();
|
||||||
|
|
||||||
|
int x = 15+(w2*i);
|
||||||
|
b.xPosition = x+2;
|
||||||
|
b.yPosition = height-30;
|
||||||
|
b.width = w2-4;
|
||||||
|
|
||||||
|
buttonList.add(b);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(messageTextField == null) {
|
||||||
|
messageTextField = new GuiTextField(GuiConstants.UPLOAD_INFO_FIELD, fontRendererObj, 20, height-80, width-40, 20);
|
||||||
|
messageTextField.setEnabled(true);
|
||||||
|
messageTextField.setFocused(false);
|
||||||
|
messageTextField.setMaxStringLength(Integer.MAX_VALUE);
|
||||||
|
} else {
|
||||||
|
messageTextField.yPosition = height-80;
|
||||||
|
messageTextField.width = width-40;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tagInput == null) {
|
||||||
|
tagInput = new GuiTextField(GuiConstants.UPLOAD_TAG_INPUT, fontRendererObj, (this.width/2)+20+10, 110, Math.min(200, this.width-20-260), 20);
|
||||||
|
tagInput.setMaxStringLength(30);
|
||||||
|
} else {
|
||||||
|
tagInput.xPosition = (this.width/2)+20+10;
|
||||||
|
tagInput.width = Math.min(200, this.width-20-260);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tagPlaceholder == null) {
|
||||||
|
tagPlaceholder = new GuiTextField(GuiConstants.UPLOAD_TAG_PLACEHOLDER, fontRendererObj, (this.width/2)+20+10, 110, Math.min(200, this.width-20-260), 20);
|
||||||
|
tagPlaceholder.setTextColor(Color.DARK_GRAY.getRGB());
|
||||||
|
tagPlaceholder.setText("Tags separated by comma");
|
||||||
|
} else {
|
||||||
|
tagPlaceholder.xPosition = (this.width/2)+20+10;
|
||||||
|
tagPlaceholder.width = Math.min(200, this.width-20-260);
|
||||||
|
}
|
||||||
|
|
||||||
|
validateStartButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -185,7 +243,15 @@ public class GuiUploadFile extends GuiScreen {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
uploader.uploadFile(GuiUploadFile.this, AuthenticationHandler.getKey(), name, replayFile, category);
|
String tagsRaw = tagInput.getText();
|
||||||
|
String[] split = tagsRaw.split(",");
|
||||||
|
List<String> tags = new ArrayList<String>();
|
||||||
|
for(String str : split) {
|
||||||
|
if(!tags.contains(str) && str.length() > 0) {
|
||||||
|
tags.add(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uploader.uploadFile(GuiUploadFile.this, AuthenticationHandler.getKey(), name, tags, replayFile, category);
|
||||||
} catch (ApiException e) { //TODO: Error handling
|
} catch (ApiException e) { //TODO: Error handling
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
//mc.displayGuiScreen(new GuiMainMenu());
|
//mc.displayGuiScreen(new GuiMainMenu());
|
||||||
@@ -232,7 +298,12 @@ public class GuiUploadFile extends GuiScreen {
|
|||||||
|
|
||||||
fileTitleInput.drawTextBox();
|
fileTitleInput.drawTextBox();
|
||||||
messageTextField.drawTextBox();
|
messageTextField.drawTextBox();
|
||||||
|
|
||||||
|
if(tagInput.getText().length() > 0 || tagInput.isFocused()) {
|
||||||
tagInput.drawTextBox();
|
tagInput.drawTextBox();
|
||||||
|
} else {
|
||||||
|
tagPlaceholder.drawTextBox();
|
||||||
|
}
|
||||||
|
|
||||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
@@ -253,11 +324,13 @@ public class GuiUploadFile extends GuiScreen {
|
|||||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||||
fileTitleInput.mouseClicked(mouseX, mouseY, mouseButton);
|
fileTitleInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||||
|
tagInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateScreen() {
|
public void updateScreen() {
|
||||||
fileTitleInput.updateCursorCounter();
|
fileTitleInput.updateCursorCounter();
|
||||||
|
tagInput.updateCursorCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -265,22 +338,38 @@ public class GuiUploadFile extends GuiScreen {
|
|||||||
Keyboard.enableRepeatEvents(false);
|
Keyboard.enableRepeatEvents(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern p = Pattern.compile("[^a-z0-9 \\-_]", Pattern.CASE_INSENSITIVE);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||||
if(fileTitleInput.isFocused()) {
|
if(fileTitleInput.isFocused()) {
|
||||||
fileTitleInput.textboxKeyTyped(typedChar, keyCode);
|
fileTitleInput.textboxKeyTyped(typedChar, keyCode);
|
||||||
|
} else if(tagInput.isFocused()) {
|
||||||
|
tagInput.textboxKeyTyped(typedChar, keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uploader.isUploading()) {
|
if(uploader.isUploading()) {
|
||||||
startUploadButton.enabled = false;
|
startUploadButton.enabled = false;
|
||||||
} else {
|
} else {
|
||||||
startUploadButton.enabled = (!(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30 ||
|
validateStartButton();
|
||||||
p.matcher(fileTitleInput.getText()).find()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateStartButton() {
|
||||||
|
boolean enabled = true;
|
||||||
|
if(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30) {
|
||||||
|
enabled = false;
|
||||||
|
} else if(p.matcher(fileTitleInput.getText()).find()) {
|
||||||
|
enabled = false;
|
||||||
|
fileTitleInput.setTextColor(Color.RED.getRGB());
|
||||||
|
} else if(pt.matcher(tagInput.getText()).find()) {
|
||||||
|
enabled = false;
|
||||||
|
tagInput.setTextColor(Color.RED.getRGB());
|
||||||
|
} else {
|
||||||
|
fileTitleInput.setTextColor(Color.WHITE.getRGB());
|
||||||
|
tagInput.setTextColor(Color.WHITE.getRGB());
|
||||||
|
}
|
||||||
|
startUploadButton.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
public void onStartUploading() {
|
public void onStartUploading() {
|
||||||
startUploadButton.enabled = false;
|
startUploadButton.enabled = false;
|
||||||
cancelUploadButton.enabled = true;
|
cancelUploadButton.enabled = true;
|
||||||
@@ -292,8 +381,7 @@ public class GuiUploadFile extends GuiScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onFinishUploading(boolean success, String info) {
|
public void onFinishUploading(boolean success, String info) {
|
||||||
startUploadButton.enabled = (!(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30 ||
|
validateStartButton();
|
||||||
p.matcher(fileTitleInput.getText()).find()));
|
|
||||||
cancelUploadButton.enabled = false;
|
cancelUploadButton.enabled = false;
|
||||||
backButton.enabled = true;
|
backButton.enabled = true;
|
||||||
categoryButton.enabled = true;
|
categoryButton.enabled = true;
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
package eu.crushedpixel.replaymod.online;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
import org.apache.http.entity.ContentType;
|
|
||||||
import org.apache.http.entity.FileEntity;
|
|
||||||
|
|
||||||
public class CountingHttpEntity extends FileEntity {
|
|
||||||
|
|
||||||
private OutputStreamProgress outstream;
|
|
||||||
|
|
||||||
public class OutputStreamProgress extends OutputStream {
|
|
||||||
|
|
||||||
private final OutputStream outstream;
|
|
||||||
private volatile long bytesWritten=0;
|
|
||||||
|
|
||||||
public OutputStreamProgress(OutputStream outstream) {
|
|
||||||
this.outstream = outstream;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(int b) throws IOException {
|
|
||||||
outstream.write(b);
|
|
||||||
bytesWritten++;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(byte[] b) throws IOException {
|
|
||||||
outstream.write(b);
|
|
||||||
bytesWritten += b.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(byte[] b, int off, int len) throws IOException {
|
|
||||||
outstream.write(b, off, len);
|
|
||||||
bytesWritten += len;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flush() throws IOException {
|
|
||||||
outstream.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
outstream.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getWrittenLength() {
|
|
||||||
return bytesWritten;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CountingHttpEntity(File file, ContentType type) {
|
|
||||||
super(file, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeTo(OutputStream outstream) throws IOException {
|
|
||||||
this.outstream = new OutputStreamProgress(outstream);
|
|
||||||
super.writeTo(this.outstream);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getProgress() {
|
|
||||||
if (outstream == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
long contentLength = getContentLength();
|
|
||||||
if (contentLength <= 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
long writtenLength = outstream.getWrittenLength();
|
|
||||||
return (writtenLength/contentLength);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package eu.crushedpixel.replaymod.online.authentication;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import eu.crushedpixel.replaymod.ReplayMod;
|
import eu.crushedpixel.replaymod.ReplayMod;
|
||||||
@@ -26,6 +27,16 @@ public class AuthenticationHandler {
|
|||||||
return authkey;
|
return authkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<String> blackUUIDs = new ArrayList<String>() {
|
||||||
|
{
|
||||||
|
add("23978392a78c49cf9f5235a151fd4083"); //Hudelsohn
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static boolean isBlacklisted(String uuid) {
|
||||||
|
return blackUUIDs.contains(uuid.replace("-", ""));
|
||||||
|
}
|
||||||
|
|
||||||
public static int authenticate(String username, String password) {
|
public static int authenticate(String username, String password) {
|
||||||
try {
|
try {
|
||||||
authkey = ReplayMod.apiClient.getLogin(username, password).getAuthkey();
|
authkey = ReplayMod.apiClient.getLogin(username, password).getAuthkey();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package eu.crushedpixel.replaymod.renderer;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.EntityRenderer;
|
import net.minecraft.client.renderer.EntityRenderer;
|
||||||
import net.minecraft.client.resources.IResourceManager;
|
import net.minecraft.client.resources.IResourceManager;
|
||||||
@@ -11,7 +12,7 @@ public class SafeEntityRenderer extends EntityRenderer {
|
|||||||
private static Field resourceManager;
|
private static Field resourceManager;
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
resourceManager = EntityRenderer.class.getDeclaredField("resourceManager"); //TODO: MCPNames
|
resourceManager = EntityRenderer.class.getDeclaredField(MCPNames.field("field_147711_ac"));
|
||||||
resourceManager.setAccessible(true);
|
resourceManager.setAccessible(true);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class PacketDeserializer extends MessageDeserializer {
|
|||||||
|
|
||||||
Field state_by_id = null;
|
Field state_by_id = null;
|
||||||
try {
|
try {
|
||||||
state_by_id = EnumConnectionState.class.getDeclaredField("STATES_BY_ID"); //TODO: Localize
|
state_by_id = EnumConnectionState.class.getDeclaredField(MCPNames.field("field_150764_e"));
|
||||||
state_by_id.setAccessible(true);
|
state_by_id.setAccessible(true);
|
||||||
state = (EnumConnectionState)((TIntObjectMap)state_by_id.get(null)).get(i);
|
state = (EnumConnectionState)((TIntObjectMap)state_by_id.get(null)).get(i);
|
||||||
TIntObjectMap map = (TIntObjectMap)state_by_id.get(null);
|
TIntObjectMap map = (TIntObjectMap)state_by_id.get(null);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
|
import java.io.EOFException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -105,7 +106,16 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
|||||||
private Field chatPacketPosition;
|
private Field chatPacketPosition;
|
||||||
|
|
||||||
private Minecraft mc = Minecraft.getMinecraft();
|
private Minecraft mc = Minecraft.getMinecraft();
|
||||||
private Field mcTimer;
|
public static Field mcTimer;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
mcTimer = Minecraft.class.getDeclaredField(MCPNames.field("field_71428_T"));
|
||||||
|
mcTimer.setAccessible(true);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private long now = System.currentTimeMillis();
|
private long now = System.currentTimeMillis();
|
||||||
|
|
||||||
@@ -158,7 +168,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
|||||||
|
|
||||||
public void setReplaySpeed(final double d) {
|
public void setReplaySpeed(final double d) {
|
||||||
if(d != 0) this.replaySpeed = d;
|
if(d != 0) this.replaySpeed = d;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Timer timer = (Timer)mcTimer.get(mc);
|
Timer timer = (Timer)mcTimer.get(mc);
|
||||||
timer.timerSpeed = (float)d;
|
timer.timerSpeed = (float)d;
|
||||||
@@ -185,9 +194,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
|||||||
joinPacketWorldType = S01PacketJoinGame.class.getDeclaredField(MCPNames.field("field_149201_g"));
|
joinPacketWorldType = S01PacketJoinGame.class.getDeclaredField(MCPNames.field("field_149201_g"));
|
||||||
joinPacketWorldType.setAccessible(true);
|
joinPacketWorldType.setAccessible(true);
|
||||||
|
|
||||||
mcTimer = Minecraft.class.getDeclaredField(MCPNames.field("field_71428_T"));
|
|
||||||
mcTimer.setAccessible(true);
|
|
||||||
|
|
||||||
effectPacketEntityId = S1DPacketEntityEffect.class.getDeclaredField(MCPNames.field("field_149434_a"));
|
effectPacketEntityId = S1DPacketEntityEffect.class.getDeclaredField(MCPNames.field("field_149434_a"));
|
||||||
effectPacketEntityId.setAccessible(true);
|
effectPacketEntityId.setAccessible(true);
|
||||||
|
|
||||||
@@ -332,9 +338,9 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
|||||||
hasRestarted = false;
|
hasRestarted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(IOException eof) {
|
} catch(EOFException eof) {
|
||||||
setReplaySpeed(0);
|
setReplaySpeed(0);
|
||||||
}
|
} catch(IOException e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package eu.crushedpixel.replaymod.registry;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.EntityRenderer;
|
||||||
|
import net.minecraftforge.client.GuiIngameForge;
|
||||||
|
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||||
|
|
||||||
|
public class ReplayGuiRegistry {
|
||||||
|
|
||||||
|
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);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void hide() {
|
||||||
|
if(hidden) return;
|
||||||
|
GuiIngameForge.renderExperiance = false;
|
||||||
|
GuiIngameForge.renderArmor = false;
|
||||||
|
GuiIngameForge.renderAir = false;
|
||||||
|
GuiIngameForge.renderHealth = false;
|
||||||
|
GuiIngameForge.renderHotbar = false;
|
||||||
|
GuiIngameForge.renderFood = false;
|
||||||
|
GuiIngameForge.renderBossHealth = false;
|
||||||
|
GuiIngameForge.renderCrosshairs = false;
|
||||||
|
GuiIngameForge.renderHelmet = false;
|
||||||
|
GuiIngameForge.renderPortal = false;
|
||||||
|
GuiIngameForge.renderHealthMount = false;
|
||||||
|
GuiIngameForge.renderJumpBar = false;
|
||||||
|
GuiIngameForge.renderObjective = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
renderHand.set(mc.entityRenderer, false);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
hidden = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void show() {
|
||||||
|
mc.gameSettings.hideGUI = false;
|
||||||
|
|
||||||
|
GuiIngameForge.renderExperiance = true;
|
||||||
|
GuiIngameForge.renderArmor = true;
|
||||||
|
GuiIngameForge.renderAir = true;
|
||||||
|
GuiIngameForge.renderHealth = true;
|
||||||
|
GuiIngameForge.renderHotbar = true;
|
||||||
|
GuiIngameForge.renderFood = true;
|
||||||
|
GuiIngameForge.renderBossHealth = true;
|
||||||
|
GuiIngameForge.renderCrosshairs = true;
|
||||||
|
GuiIngameForge.renderHelmet = true;
|
||||||
|
GuiIngameForge.renderPortal = true;
|
||||||
|
GuiIngameForge.renderHealthMount = true;
|
||||||
|
GuiIngameForge.renderJumpBar = true;
|
||||||
|
GuiIngameForge.renderObjective = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
renderHand.set(mc.entityRenderer, true);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
hidden = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user