diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java b/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java index 942cf1b9..06bd1f66 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java @@ -161,6 +161,11 @@ public CompletableFuture getCounts() { return get(true, CountsReply.class, "counts"); } + public CompletableFuture getResourcePacks() { + return get(false, ResourcePackReply.class, "resources/packs",null, 5L); + } + + /** * Gets the current status of the player with information about the server they are in * at that moment. @@ -208,6 +213,28 @@ public CompletableFuture getPetRepository() { .thenApply(PetRepositoryImpl::new); } + /** + * @param profile Profile ID of which you are requesting the Garden for. + * @return the future + */ + public CompletableFuture getSkyBlockGarden(String profile) { + return get(true, SkyBlockGardenReply.class, "skyblock/garden", + HTTPQueryParams.create() + .add("profile", profile) + ); + } + + /** + * @param profile Profile ID of which you are requesting the Museum for. + * @return the future + */ + public CompletableFuture getSkyblockMuseum(String profile) { + return get(true, SkyBlockMuseumReply.class, "skyblock/museum", + HTTPQueryParams.create() + .add("profile", profile) + ); + } + public CompletableFuture getSkyBlockProfile(String profile) { return get(true, SkyBlockProfileReply.class, "skyblock/profile", HTTPQueryParams.create() diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/ResourcePackReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/ResourcePackReply.java new file mode 100644 index 00000000..2ba957e5 --- /dev/null +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/ResourcePackReply.java @@ -0,0 +1,58 @@ +package net.hypixel.api.reply; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Comparator; +import java.util.List; +import java.util.UUID; + +public class ResourcePackReply extends AbstractReply { + public List packs; + + /** + * Convenience function. + * @return Skyblock Resource Pack. + * @throws IllegalAccessException if no resourcepack with the configured id is found. + */ + public ResourcePack getSkyblockPack() throws IllegalAccessException { + return packs.stream().filter(a -> a.gameId.equals("SkyBlock")).findFirst().orElseThrow(()->new IllegalAccessException("SkyBlock pack not found")); + } + + + public static class ResourcePack { + /** + * For example "SkyBlock" + */ + public String gameId; + public Long lastUpdated; + public UUID deployUUID; + public List versions; + public VersionResourcePack latest(){ + return versions.stream().max(Comparator.comparingInt(a -> a.packFormat)).orElse(null); + } + } + + public static class VersionResourcePack { + /** + * These are the mc packformats used. + */ + public int packFormat; + public String url; + public String hash; + + /** + * Downloads the file from the download url to the specified file. Note that this is a Zip Archive! + */ + public void downloadToFile(File file) throws IOException { + URL url = new URL(this.url); + try (InputStream in = url.openStream()) { + Files.copy(in, Paths.get(file.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING); + } + } + } +} diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/SkyBlockGardenReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/SkyBlockGardenReply.java new file mode 100644 index 00000000..3367fa97 --- /dev/null +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/SkyBlockGardenReply.java @@ -0,0 +1,24 @@ +package net.hypixel.api.reply.skyblock; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.hypixel.api.reply.RateLimitedReply; + +public class SkyBlockGardenReply extends RateLimitedReply { + private JsonElement garden; + + public JsonObject getGarden() { + if (garden == null || garden.isJsonNull()) { + return null; + } else { + return garden.getAsJsonObject(); + } + } + + @Override + public String toString() { + return "SkyBlockGardenReply{" + + "profile=" + garden + + "} " + super.toString(); + } +} diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/SkyBlockMuseumReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/SkyBlockMuseumReply.java new file mode 100644 index 00000000..137477f9 --- /dev/null +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/SkyBlockMuseumReply.java @@ -0,0 +1,24 @@ +package net.hypixel.api.reply.skyblock; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.hypixel.api.reply.RateLimitedReply; + +public class SkyBlockMuseumReply extends RateLimitedReply { + private JsonElement members; + + public JsonObject getMuseum() { + if (members == null || members.isJsonNull()) { + return null; + } else { + return members.getAsJsonObject(); + } + } + + @Override + public String toString() { + return "SkyBlockMuseumReply{" + + "profile=" + members + + "} " + super.toString(); + } +} diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/util/ResourceType.java b/hypixel-api-core/src/main/java/net/hypixel/api/util/ResourceType.java index 66fa34ab..fe1399a7 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/util/ResourceType.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/util/ResourceType.java @@ -13,7 +13,7 @@ public enum ResourceType { SKYBLOCK_ITEMS("skyblock/items"), SKYBLOCK_ELECTION("skyblock/election"), SKYBLOCK_BINGO("skyblock/bingo"), - ; + RESOURCE_PACKS("resourcepacks"),; /** * Path to resource