aboutsummaryrefslogtreecommitdiff
path: root/me/Danker/handlers/APIHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'me/Danker/handlers/APIHandler.java')
-rw-r--r--me/Danker/handlers/APIHandler.java37
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();