Skip to content

Commit 9cfdc86

Browse files
committed
Fix shop endpoint cooldown
1 parent 6852978 commit 9cfdc86

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/java/net/earthmc/emcapi/endpoint/ShopEndpoint.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.UUID;
2020
import java.util.concurrent.CompletableFuture;
2121
import java.util.concurrent.ConcurrentHashMap;
22-
import java.util.concurrent.ConcurrentHashMap;
2322
import java.util.concurrent.TimeUnit;
2423

2524
public class ShopEndpoint extends PostEndpoint<List<Shop>> {
@@ -34,7 +33,7 @@ public ShopEndpoint(EMCAPI plugin) {
3433
LAST_QUERY_MAP.entrySet().removeIf(entry -> entry.getValue() < Instant.now().getEpochSecond() - COOLDOWN_SECONDS),
3534
1,
3635
1,
37-
TimeUnit.HOURS
36+
TimeUnit.MINUTES // Check more often
3837
);
3938
}
4039

@@ -62,6 +61,14 @@ public JsonElement getJsonElement(List<Shop> object, @Nullable String key) {
6261
if (keyOwner == null) {
6362
return null;
6463
}
64+
if (LAST_QUERY_MAP.containsKey(keyOwner) && LAST_QUERY_MAP.get(keyOwner) > Instant.now().getEpochSecond() - COOLDOWN_SECONDS) {
65+
return null;
66+
}
67+
if (object.isEmpty()) {
68+
return null;
69+
} else {
70+
LAST_QUERY_MAP.put(keyOwner, Instant.now().getEpochSecond());
71+
}
6572

6673
final List<CompletableFuture<Void>> shopFutures = new ArrayList<>();
6774

@@ -87,7 +94,6 @@ public JsonElement getJsonElement(List<Shop> object, @Nullable String key) {
8794

8895
CompletableFuture.allOf(shopFutures.toArray(new CompletableFuture[]{})).join();
8996
if (shops.isEmpty()) {
90-
LAST_QUERY_MAP.put(keyOwner, Instant.now().getEpochSecond());
9197
return null;
9298
}
9399

0 commit comments

Comments
 (0)