diff options
| author | Roman / Nea <roman.graef@gmail.com> | 2022-05-31 20:53:26 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-31 20:53:26 +0200 |
| commit | dfdc2d9519556dfec528ab9d1732cdf32aab0639 (patch) | |
| tree | 6f046db7b581f40b2deedd202ceaf98ba9ec2567 /src/main/java/io/github/moulberry/notenoughupdates/util | |
| parent | a6546a1abe954b394c40be58d73d6fb03d93709e (diff) | |
| download | notenoughupdates-dfdc2d9519556dfec528ab9d1732cdf32aab0639.tar.gz notenoughupdates-dfdc2d9519556dfec528ab9d1732cdf32aab0639.tar.bz2 notenoughupdates-dfdc2d9519556dfec528ab9d1732cdf32aab0639.zip | |
Move repository related configuration to GUI. (#151)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util')
3 files changed, 3 insertions, 35 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java index 7258fe9f..800c025a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java @@ -141,7 +141,7 @@ public class HotmInformation { public synchronized void requestUpdate(boolean force) { if (updateTask.isDone() || force) { updateTask = neu.manager.hypixelApi.getHypixelApiAsync( - neu.config.apiKey.apiKey, + neu.config.apiData.apiKey, "skyblock/profiles", new HashMap<String, String>() {{ put("uuid", Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")); 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 37de9ed8..937a0ab8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java @@ -21,14 +21,8 @@ import java.util.function.Consumer; import java.util.zip.GZIPInputStream; public class HypixelApi { - private static final int FAILS_BEFORE_SWITCH = 3; private final Gson gson = new Gson(); private final ExecutorService es = Executors.newFixedThreadPool(3); - 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}; - private int currentUrl = 0; - private long lastPrimaryUrl = 0; public CompletableFuture<JsonObject> getHypixelApiAsync(String apiKey, String method, HashMap<String, String> args) { return getApiAsync(generateApiUrl(apiKey, method, args)); @@ -55,29 +49,7 @@ public class HypixelApi { } private String getMyApiURL() { - if (currentUrl == 0) { - lastPrimaryUrl = System.currentTimeMillis(); - } else if (System.currentTimeMillis() - lastPrimaryUrl > 1000 * 60 * 30) { //Try switch back to main url after 30m - currentUrl = 0; - } - - myApiSuccesses[currentUrl] = Math.min(FAILS_BEFORE_SWITCH, myApiSuccesses[currentUrl] + 1); - return myApiURLs[currentUrl]; - } - - private void myApiError(int index) { - myApiSuccesses[index] = myApiSuccesses[index] - 2; - - if (myApiSuccesses[index] < 0) { - myApiSuccesses[index] = 0; - - if (index == currentUrl) { - currentUrl++; - if (currentUrl >= myApiURLs.length) { - currentUrl = 0; - } - } - } + return String.format("https://%s/", NotEnoughUpdates.INSTANCE.config.apiData.moulberryCodesApi); } public CompletableFuture<JsonObject> getApiAsync(String urlS) { @@ -104,14 +76,12 @@ public class HypixelApi { public void getMyApiAsync(String urlS, Consumer<JsonObject> consumer, Runnable error) { es.submit(() -> { - int current = currentUrl; try { consumer.accept(getApiSync(getMyApiURL() + urlS)); } catch (Exception e) { if (NotEnoughUpdates.INSTANCE.config.hidden.dev) { e.printStackTrace(); } - myApiError(current); error.run(); } }); @@ -119,11 +89,9 @@ public class HypixelApi { public void getMyApiGZIPAsync(String urlS, Consumer<JsonObject> consumer, Runnable error) { es.submit(() -> { - int current = currentUrl; try { consumer.accept(getApiGZIPSync(getMyApiURL() + urlS)); } catch (Exception e) { - myApiError(current); error.run(); } }); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java index b4193c88..5ee1dda1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java @@ -30,7 +30,7 @@ public class JsonUtils { String name, Function<? super JsonElement, ? extends T> mapper ) { - if (!rootObject.has(name)) { + if (rootObject == null || !rootObject.has(name)) { return Collections.emptyList(); } JsonElement jsonElement = rootObject.get(name); |
