Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Java/src/main/java/net/hypixel/api/HypixelAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ private <R extends AbstractReply> CompletableFuture<R> get(Class<R> 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 {
Expand Down
23 changes: 23 additions & 0 deletions Java/src/main/java/net/hypixel/api/reply/AbstractReply.java
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -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 +
'}';
}
}
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<version>2.0-SNAPSHOT</version>

<modules>
<module>Example</module>
<!--Removed due to incorrect reference https://github.com/HypixelDev/PublicAPI/pull/342 fixed this already-->
<!--<module>Example</module>-->
<module>Java</module>
</modules>

Expand Down