|
| 1 | +package net.hypixel.api.reply; |
| 2 | + |
| 3 | +import com.google.gson.JsonObject; |
| 4 | +import com.jetbrains.cef.remote.thrift.annotation.Nullable; |
| 5 | +import java.io.File; |
| 6 | +import java.io.IOException; |
| 7 | +import java.io.InputStream; |
| 8 | +import java.net.URL; |
| 9 | +import java.nio.file.Files; |
| 10 | +import java.nio.file.Paths; |
| 11 | +import java.nio.file.StandardCopyOption; |
| 12 | +import java.util.Comparator; |
| 13 | +import java.util.List; |
| 14 | +import java.util.UUID; |
| 15 | + |
| 16 | +public class ResourcePackReply { |
| 17 | + List<ResourcePack> packs; |
| 18 | + |
| 19 | + /** |
| 20 | + * Convenience function. |
| 21 | + * @return Skyblock Resource Pack. |
| 22 | + * @throws IllegalAccessException if no resourcepack with the configured id is found. |
| 23 | + */ |
| 24 | + ResourcePack getSkyblockPack() throws IllegalAccessException { |
| 25 | + return packs.stream().filter(a -> a.gameId.equals("SkyBlock")).findFirst().orElseThrow(()->new IllegalAccessException("SkyBlock pack not found")); |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | + static class ResourcePack { |
| 30 | + /** |
| 31 | + * For example "SkyBlock" |
| 32 | + */ |
| 33 | + String gameId; |
| 34 | + Long lastUpdated; |
| 35 | + UUID deployUUID; |
| 36 | + List<VersionResourcePack> versions; |
| 37 | + @Nullable |
| 38 | + public VersionResourcePack latest(){ |
| 39 | + return versions.stream().max(Comparator.comparingInt(a -> a.packFormat)).orElse(null); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + static class VersionResourcePack { |
| 44 | + /** |
| 45 | + * These are the mc packformats used. |
| 46 | + */ |
| 47 | + int packFormat; |
| 48 | + String url; |
| 49 | + String hash; |
| 50 | + |
| 51 | + /** |
| 52 | + * Downloads the file from the download url to the specified file. Note that this is a Zip Archive! |
| 53 | + */ |
| 54 | + public void downloadToFile(File file) throws IOException { |
| 55 | + URL url = new URL(this.url); |
| 56 | + try (InputStream in = url.openStream()) { |
| 57 | + Files.copy(in, Paths.get(file.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING); |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments