diff --git a/src/main/java/de/hysky/skyblocker/utils/ApiUtils.java b/src/main/java/de/hysky/skyblocker/utils/ApiUtils.java index 0121f8ad5f..c63af3ba28 100644 --- a/src/main/java/de/hysky/skyblocker/utils/ApiUtils.java +++ b/src/main/java/de/hysky/skyblocker/utils/ApiUtils.java @@ -31,6 +31,10 @@ public static void init() { * Multithreading is to be handled by the method caller */ public static String name2Uuid(String name) { + return name2Uuid(name, 0); + } + + private static String name2Uuid(String name, int retries) { Session session = MinecraftClient.getInstance().getSession(); if (session.getUsername().equals(name)) return UndashedUuid.toString(session.getUuidOrNull()); @@ -43,6 +47,10 @@ public static String name2Uuid(String name) { NAME_2_UUID_CACHE.put(name, uuid); return uuid; + } else if (response.ratelimited() && retries < 3) { + Thread.sleep(800); + + return name2Uuid(name, ++retries); } } catch (Exception e) { LOGGER.error("[Skyblocker] Name to uuid lookup failed! Name: {}", name, e); diff --git a/src/main/java/de/hysky/skyblocker/utils/Http.java b/src/main/java/de/hysky/skyblocker/utils/Http.java index eced3c08b7..17079d15aa 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Http.java +++ b/src/main/java/de/hysky/skyblocker/utils/Http.java @@ -134,6 +134,10 @@ public boolean ok() { return statusCode == 200; } + public boolean ratelimited() { + return statusCode == 429; + } + public boolean cached() { return cacheStatus.equals("HIT"); }