diff options
author | Torui <44932079+ToruiDev@users.noreply.github.com> | 2022-05-21 16:11:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-21 16:11:01 +0200 |
commit | b9b1294882b68e2d85aec0c1d28570f5d68359b9 (patch) | |
tree | 599b996aa7844a4bc9d989d75f879c5a065e6c55 /src/main/java/de/torui/coflsky/network | |
parent | 4a85bf6754c101b43d2d0d3a6c9ed5744dd0308d (diff) | |
download | COFL-b9b1294882b68e2d85aec0c1d28570f5d68359b9.tar.gz COFL-b9b1294882b68e2d85aec0c1d28570f5d68359b9.tar.bz2 COFL-b9b1294882b68e2d85aec0c1d28570f5d68359b9.zip |
initial implementation (#38)
* 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 <xekwavx@gmail.com>
Diffstat (limited to 'src/main/java/de/torui/coflsky/network')
-rw-r--r-- | src/main/java/de/torui/coflsky/network/QueryServerCommands.java | 49 |
1 files changed, 44 insertions, 5 deletions
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 { @@ -102,4 +101,44 @@ public class QueryServerCommands { 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; + } } |