Skip to content

Commit 6ee6de1

Browse files
committed
added reosurcepack api like for skyblock
1 parent 85d537d commit 6ee6de1

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ public CompletableFuture<CountsReply> getCounts() {
161161
return get(true, CountsReply.class, "counts");
162162
}
163163

164+
public CompletableFuture<ResourceReply> getResourcePacks() {
165+
return get(true, ResourceReply.class, "counts");
166+
}
167+
168+
164169
/**
165170
* Gets the current status of the player with information about the server they are in
166171
* at that moment.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)