aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
diff options
context:
space:
mode:
authorMoulberry <james.jenour@student.scotch.wa.edu.au>2020-08-19 12:16:12 +1000
committerMoulberry <james.jenour@student.scotch.wa.edu.au>2020-08-19 12:16:12 +1000
commitea1391e0c6f0db863bbb61511eb6e9acb57a5968 (patch)
tree16e0b8a76055838b6cc1963f56c1327cd8850c66 /src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
parent0c23f52d2be811d74a3b6ef598dd9de7ccb763ab (diff)
downloadnotenoughupdates-ea1391e0c6f0db863bbb61511eb6e9acb57a5968.tar.gz
notenoughupdates-ea1391e0c6f0db863bbb61511eb6e9acb57a5968.tar.bz2
notenoughupdates-ea1391e0c6f0db863bbb61511eb6e9acb57a5968.zip
1.1.5
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java29
1 files changed, 29 insertions, 0 deletions
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 ca6c30af..b925f6da 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
@@ -23,6 +23,9 @@ public class HypixelApi {
private Gson gson = new Gson();
private ExecutorService es = Executors.newFixedThreadPool(3);
+ private int myApiErrors = 0;
+ private String[] myApiURLs = {"https://moulberry.codes/", "https://51.89.22.3/", "http://moulberry.codes/", "http://51.89.22.3/"};
+
public void getHypixelApiAsync(String apiKey, String method, HashMap<String, String> args, Consumer<JsonObject> consumer) {
getHypixelApiAsync(apiKey, method, args, consumer, () -> {});
}
@@ -31,6 +34,10 @@ public class HypixelApi {
getApiAsync(generateApiUrl(apiKey.trim(), method, args), consumer, error);
}
+ private String getMyApiURL() {
+ return myApiURLs[myApiErrors%myApiURLs.length];
+ }
+
public void getApiAsync(String urlS, Consumer<JsonObject> consumer, Runnable error) {
es.submit(() -> {
try {
@@ -41,6 +48,28 @@ public class HypixelApi {
});
}
+ public void getMyApiAsync(String urlS, Consumer<JsonObject> consumer, Runnable error) {
+ es.submit(() -> {
+ try {
+ consumer.accept(getApiSync(getMyApiURL()+urlS));
+ } catch(IOException e) {
+ myApiErrors++;
+ error.run();
+ }
+ });
+ }
+
+ public void getMyApiGZIPAsync(String urlS, Consumer<JsonObject> consumer, Runnable error) {
+ es.submit(() -> {
+ try {
+ consumer.accept(getApiGZIPSync(getMyApiURL()+urlS));
+ } catch(IOException e) {
+ myApiErrors++;
+ error.run();
+ }
+ });
+ }
+
public void getApiGZIPAsync(String urlS, Consumer<JsonObject> consumer, Runnable error) {
es.submit(() -> {
try {