Skip to content

Commit 1037fbb

Browse files
committed
added reosurcepack api like for skyblock
1 parent 85d537d commit 1037fbb

3 files changed

Lines changed: 65 additions & 1 deletion

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

hypixel-api-core/src/main/java/net/hypixel/api/util/ResourceType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public enum ResourceType {
1313
SKYBLOCK_ITEMS("skyblock/items"),
1414
SKYBLOCK_ELECTION("skyblock/election"),
1515
SKYBLOCK_BINGO("skyblock/bingo"),
16-
;
16+
RESOURCE_PACKS("resourcepacks"),;
1717

1818
/**
1919
* Path to resource

0 commit comments

Comments
 (0)