diff --git a/Java/src/main/java/net/hypixel/api/HypixelAPI.java b/Java/src/main/java/net/hypixel/api/HypixelAPI.java index bb5835a9..5264204e 100644 --- a/Java/src/main/java/net/hypixel/api/HypixelAPI.java +++ b/Java/src/main/java/net/hypixel/api/HypixelAPI.java @@ -248,6 +248,12 @@ private CompletableFuture get(Class clazz, Strin try { R response = httpClient.execute(new HttpGet(url.toString()), obj -> { String content = EntityUtils.toString(obj.getEntity(), "UTF-8"); + content = content.substring(0, content.length() - 1).concat( + "\"" + AbstractReply.REQUEST_REMAINING_FIELD_NAME + "\":" + + obj.getFirstHeader("ratelimit-remaining").getValue() + + ",\"" + AbstractReply.TIME_UNTIL_RESET_FIELD_NAME + "\":" + + obj.getFirstHeader("ratelimit-reset").getValue() + "}" + ); if (clazz == ResourceReply.class) { return (R) new ResourceReply(GSON.fromJson(content, JsonObject.class)); } else { diff --git a/Java/src/main/java/net/hypixel/api/reply/AbstractReply.java b/Java/src/main/java/net/hypixel/api/reply/AbstractReply.java index d0bd15ff..8776060a 100644 --- a/Java/src/main/java/net/hypixel/api/reply/AbstractReply.java +++ b/Java/src/main/java/net/hypixel/api/reply/AbstractReply.java @@ -1,11 +1,21 @@ package net.hypixel.api.reply; +import com.google.gson.annotations.SerializedName; + public abstract class AbstractReply { protected boolean throttle; protected boolean success; protected String cause; + public static final String REQUEST_REMAINING_FIELD_NAME = "requests_remaining"; + public static final String TIME_UNTIL_RESET_FIELD_NAME = "time_until_reset"; + + @SerializedName(REQUEST_REMAINING_FIELD_NAME) + protected final int requestAmountRemaining = -1; // -1 indicates this field has not been deserialized yet + @SerializedName(TIME_UNTIL_RESET_FIELD_NAME) + protected final int timeUntilLimitReset = -1; // -1 indicates this field has not been deserialized yet + public boolean isThrottle() { return throttle; } @@ -18,12 +28,25 @@ public String getCause() { return cause; } + public int getRequestAmountRemaining() + { + return requestAmountRemaining; + } + + public int getSecondsUntilReset() + { + return timeUntilLimitReset; + } + + @Override public String toString() { return "AbstractReply{" + "throttle=" + throttle + ", success=" + success + ", cause='" + cause + '\'' + + ", limit_left=" + requestAmountRemaining + + ", limit_reset=" + timeUntilLimitReset + '}'; } } diff --git a/pom.xml b/pom.xml index 0df9c032..fa5f4a6d 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,8 @@ 2.0-SNAPSHOT - Example + + Java