aboutsummaryrefslogtreecommitdiff
path: root/me/Danker/handlers
diff options
context:
space:
mode:
authorbowser0000 <bowser0000@gmail.com>2020-07-18 22:26:30 -0400
committerbowser0000 <bowser0000@gmail.com>2020-07-18 22:26:30 -0400
commitd1f260be47ea166e77b2e25cd07d6b08ec3e767d (patch)
tree0acc0db6c83d0cc0c5943809ca15dd6660de902d /me/Danker/handlers
parent94b09d4895ccffcbb3f96eabb1a5e935fc5221b6 (diff)
downloadSkyblockMod-d1f260be47ea166e77b2e25cd07d6b08ec3e767d.tar.gz
SkyblockMod-d1f260be47ea166e77b2e25cd07d6b08ec3e767d.tar.bz2
SkyblockMod-d1f260be47ea166e77b2e25cd07d6b08ec3e767d.zip
Add /slayer, API handling and better number formatsv1.5
Added API handler which should make future API commands easier to add. Added /slayer command. Added format to numbers based on locale.
Diffstat (limited to 'me/Danker/handlers')
-rw-r--r--me/Danker/handlers/APIHandler.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/me/Danker/handlers/APIHandler.java b/me/Danker/handlers/APIHandler.java
new file mode 100644
index 0000000..5997713
--- /dev/null
+++ b/me/Danker/handlers/APIHandler.java
@@ -0,0 +1,51 @@
+package me.Danker.handlers;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.EnumChatFormatting;
+
+public class APIHandler {
+ public static JsonObject getResponse(String urlString, EntityPlayer player) {
+ 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();
+ JsonObject object = gson.fromJson(response.toString(), JsonObject.class);
+
+ return object;
+ } else {
+ player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Request failed. Incorrect arguments?"));
+ }
+ } 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 JsonObject();
+ }
+}