diff options
author | bowser0000 <bowser0000@gmail.com> | 2020-07-20 19:27:24 -0400 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2020-07-20 19:27:24 -0400 |
commit | 2f128b7995cded35f9b0ca41f5ef6fa70d633b7f (patch) | |
tree | 0b3787ce7df788c64f25125422c80c3fc1e159ec /me/Danker/handlers/APIHandler.java | |
parent | 34234ac4f58c66c3910e635aaaad60ebf08e9b00 (diff) | |
download | SkyblockMod-2f128b7995cded35f9b0ca41f5ef6fa70d633b7f.tar.gz SkyblockMod-2f128b7995cded35f9b0ca41f5ef6fa70d633b7f.tar.bz2 SkyblockMod-2f128b7995cded35f9b0ca41f5ef6fa70d633b7f.zip |
/dhelp, /guildof, fix brackets
Add /dhelp which returns list of commands. Add /guildof which returns guild and guildmaster of a person. Swap <> and [] for parameters.
Diffstat (limited to 'me/Danker/handlers/APIHandler.java')
-rw-r--r-- | me/Danker/handlers/APIHandler.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/me/Danker/handlers/APIHandler.java b/me/Danker/handlers/APIHandler.java index 94868a2..006842b 100644 --- a/me/Danker/handlers/APIHandler.java +++ b/me/Danker/handlers/APIHandler.java @@ -54,6 +54,43 @@ public class APIHandler { return new JsonObject(); } + // Only used for UUID => Username + public static JsonArray getArrayResponse(String urlString) { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + + try { + URL url = new URL(urlString); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + + if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { + BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String input; + StringBuffer response = new StringBuffer(); + + while ((input = in.readLine()) != null) { + response.append(input); + } + in.close(); + + Gson gson = new Gson(); + JsonArray array = gson.fromJson(response.toString(), JsonArray.class); + + return array; + } else { + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Request failed. HTTP Error Code: " + conn.getResponseCode())); + } + } catch (MalformedURLException ex) { + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "An error has occured. See logs for more details.")); + System.err.println(ex); + } catch (IOException ex) { + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "An error has occured. See logs for more details.")); + System.err.println(ex); + } + + return new JsonArray(); + } + public static String getUUID(String username) { Gson gson = new Gson(); |