From 9ae63509ab33c4d3f0ee19bc618ef4e4c654ef46 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 31 Dec 2020 01:26:26 +0800 Subject: 1.8-PRE1 --- .../moulberry/notenoughupdates/util/HypixelApi.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java index db630b84..c237959a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java @@ -26,7 +26,7 @@ public class HypixelApi { private static final int FAILS_BEFORE_SWITCH = 3; private int currentUrl = 0; private long lastPrimaryUrl = 0; - private final String[] myApiURLs = {"https://moulberry.codes/", "http://51.79.51.21/", "http://moulberry.codes/", "http://51.75.78.252/" }; + private final String[] myApiURLs = {"https://moulberry.codes/"};//, "http://moulberry.codes/", "http://51.79.51.21/"};//, "http://51.75.78.252/" }; private final Integer[] myApiSuccesses = {0, 0, 0, 0}; public void getHypixelApiAsync(String apiKey, String method, HashMap args, Consumer consumer) { @@ -34,7 +34,7 @@ public class HypixelApi { } public void getHypixelApiAsync(String apiKey, String method, HashMap args, Consumer consumer, Runnable error) { - getApiAsync(generateApiUrl(apiKey.trim(), method, args), consumer, error); + getApiAsync(generateApiUrl(apiKey!=null?apiKey.trim():null, method, args), consumer, error); } private String getMyApiURL() { @@ -79,6 +79,7 @@ public class HypixelApi { try { consumer.accept(getApiSync(getMyApiURL()+urlS)); } catch(Exception e) { + e.printStackTrace(); myApiError(current); error.run(); } @@ -132,9 +133,16 @@ public class HypixelApi { } public String generateApiUrl(String apiKey, String method, HashMap args) { - StringBuilder url = new StringBuilder("https://api.hypixel.net/" + method + "?key=" + apiKey); + StringBuilder url = new StringBuilder("https://api.hypixel.net/" + method + (apiKey != null ? ("?key=" + apiKey) : "")); + boolean first = true; for(Map.Entry entry : args.entrySet()) { - url.append("&").append(entry.getKey()).append("=").append(entry.getValue()); + if(first && apiKey == null) { + url.append("?"); + first = false; + } else { + url.append("&"); + } + url.append(entry.getKey()).append("=").append(entry.getValue()); } return url.toString(); } -- cgit