mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-09-10 01:28:19 +02:00
Fix inconsistancy in request delay obey
This commit is contained in:
parent
1c85ba7586
commit
4c7ba6a9ad
@ -180,8 +180,8 @@ public class MineSkinAPI {
|
|||||||
|
|
||||||
callback.onError(LibsMsg.SKIN_API_FAIL);
|
callback.onError(LibsMsg.SKIN_API_FAIL);
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
|
||||||
nextRequest = System.currentTimeMillis() + nextRequestIn + 1000;
|
nextRequest = System.currentTimeMillis() + nextRequestIn + 1000;
|
||||||
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -190,6 +190,18 @@ public class MineSkinAPI {
|
|||||||
public MineSkinResponse generateFromUUID(UUID uuid, SkinUtils.ModelType modelType) throws IllegalArgumentException {
|
public MineSkinResponse generateFromUUID(UUID uuid, SkinUtils.ModelType modelType) throws IllegalArgumentException {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
|
||||||
|
long sleep = nextRequest - System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (sleep > 0) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(sleep);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long nextRequestIn = TimeUnit.SECONDS.toMillis(10);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String siteUrl = "https://api.mineskin.org/generate/user/:" + uuid.toString();
|
String siteUrl = "https://api.mineskin.org/generate/user/:" + uuid.toString();
|
||||||
|
|
||||||
@ -210,13 +222,11 @@ public class MineSkinAPI {
|
|||||||
|
|
||||||
MineSkinResponse skinResponse = new Gson().fromJson(response, MineSkinResponse.class);
|
MineSkinResponse skinResponse = new Gson().fromJson(response, MineSkinResponse.class);
|
||||||
|
|
||||||
nextRequest = System.currentTimeMillis() + (long) (skinResponse.getNextRequest() * 1000);
|
nextRequestIn = (long) (skinResponse.getNextRequest() * 1000);
|
||||||
|
|
||||||
return skinResponse;
|
return skinResponse;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
nextRequest = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
|
|
||||||
|
|
||||||
if (ex.getMessage() != null && ex.getMessage().contains("Server returned HTTP response code: 400 for URL")) {
|
if (ex.getMessage() != null && ex.getMessage().contains("Server returned HTTP response code: 400 for URL")) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
@ -224,6 +234,7 @@ public class MineSkinAPI {
|
|||||||
DisguiseUtilities.getLogger().warning("Failed to access MineSkin.org");
|
DisguiseUtilities.getLogger().warning("Failed to access MineSkin.org");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
|
nextRequest = System.currentTimeMillis() + nextRequestIn + 1000;
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user