diff options
| author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2022-10-23 13:33:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-23 13:33:15 +0200 |
| commit | dd6a4011a95da0481b98ff472dedc7911f9a3741 (patch) | |
| tree | c526a50c3dd178cc55b6d92529e6c89d265dc0ce /src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java | |
| parent | a2e1983b47392d7724df78f842ef81bfb6f67d60 (diff) | |
| download | notenoughupdates-dd6a4011a95da0481b98ff472dedc7911f9a3741.tar.gz notenoughupdates-dd6a4011a95da0481b98ff472dedc7911f9a3741.tar.bz2 notenoughupdates-dd6a4011a95da0481b98ff472dedc7911f9a3741.zip | |
Minion Helper (#254)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: ThexXTURBOXx <nico.mexis@kabelmail.de>
Co-authored-by: efefury <69400149+efefury@users.noreply.github.com>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java index 7818c3c0..e84c1c43 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java @@ -22,6 +22,8 @@ package io.github.moulberry.notenoughupdates.util; import com.google.gson.Gson; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent; +import net.minecraft.client.Minecraft; import org.apache.commons.io.IOUtils; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URIBuilder; @@ -48,7 +50,9 @@ import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -59,6 +63,7 @@ public class ApiUtil { private static final ExecutorService executorService = Executors.newFixedThreadPool(3); private static final String USER_AGENT = "NotEnoughUpdates/" + NotEnoughUpdates.VERSION; private static SSLContext ctx; + private final Map<String, CompletableFuture<Void>> updateTasks = new HashMap<>(); static { try { @@ -77,6 +82,23 @@ public class ApiUtil { } } + public void updateProfileData() { + updateProfileData(Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")); + } + + public void updateProfileData(String playerUuid) { + if (!updateTasks.getOrDefault(playerUuid, CompletableFuture.completedFuture(null)).isDone()) return; + + updateTasks.put(playerUuid, newHypixelApiRequest("skyblock/profiles") + .queryArgument("uuid", Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")) + .requestJson() + .handle((jsonObject, throwable) -> { + new ProfileDataLoadedEvent(jsonObject).post(); + return null; + })); + + } + public static class Request { private final List<NameValuePair> queryArguments = new ArrayList<>(); |
