From 2f128b7995cded35f9b0ca41f5ef6fa70d633b7f Mon Sep 17 00:00:00 2001 From: bowser0000 Date: Mon, 20 Jul 2020 19:27:24 -0400 Subject: /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. --- me/Danker/handlers/APIHandler.java | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'me/Danker/handlers') 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(); -- cgit