From b9b1294882b68e2d85aec0c1d28570f5d68359b9 Mon Sep 17 00:00:00 2001 From: Torui <44932079+ToruiDev@users.noreply.github.com> Date: Sat, 21 May 2022 16:11:01 +0200 Subject: initial implementation (#38) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * rewrite everything * Add replace and insert methods for tooltips * Add sleep bcz hypixel doesnt want a prefilled chest * Commit requested changes * Fix messed up item stacks for stackables * Move handlers to handlers package * Empty hashmap on gui close * merge conflixt fix * Fix index out of bound exception * Fix bcz forge * fix messed slot assigns when there is empoty inventory slot * Make tooltips respect mod settings * Fix typo * save tab contents * optimise description loading & fix tab Co-authored-by: HackedOS <63157139+HackedOS@users.noreply.github.com> Co-authored-by: Äkwav --- .../torui/coflsky/network/QueryServerCommands.java | 49 +++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'src/main/java/de/torui/coflsky/network') diff --git a/src/main/java/de/torui/coflsky/network/QueryServerCommands.java b/src/main/java/de/torui/coflsky/network/QueryServerCommands.java index 0bf54a3..67f8f2a 100644 --- a/src/main/java/de/torui/coflsky/network/QueryServerCommands.java +++ b/src/main/java/de/torui/coflsky/network/QueryServerCommands.java @@ -1,9 +1,6 @@ package de.torui.coflsky.network; -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.util.Arrays; @@ -12,6 +9,8 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import de.torui.coflsky.CoflSky; +import de.torui.coflsky.minecraft_integration.CoflSessionManager; +import de.torui.coflsky.minecraft_integration.PlayerDataProvider; public class QueryServerCommands { @@ -37,7 +36,7 @@ public class QueryServerCommands { } - return "§4ERROR: Could not connect to command server!"; + return "§4ERROR: Could not connect to command server!"; } private static class CommandInfo { @@ -100,6 +99,46 @@ public class QueryServerCommands { e.printStackTrace(); } + return null; + } + public static String PostRequest(String uri, String data) { + try { + String username = PlayerDataProvider.getUsername(); + URL url = new URL(uri); + HttpURLConnection con; + con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("POST"); + + con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + con.setRequestProperty("Accept", "application/json"); + con.setRequestProperty("User-Agent", "CoflMod"); + con.setRequestProperty("conId", CoflSessionManager.GetCoflSession(username).SessionUUID); + con.setRequestProperty("uuid",username); + con.setDoInput(true); + con.setDoOutput(true); + // ... + + OutputStream os = con.getOutputStream(); + byte[] bytes = data.getBytes("UTF-8"); + os.write(bytes); + os.close(); + + InputStream in = new BufferedInputStream(con.getInputStream()); + ByteArrayOutputStream result = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + for (int length; (length = in.read(buffer)) != -1; ) { + result.write(buffer, 0, length); + } + // StandardCharsets.UTF_8.name() > JDK 7 + String resString = result.toString("UTF-8"); + + System.out.println("Result= " + resString); + return resString; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; } } -- cgit