Skip to content

Commit 7d0bd63

Browse files
committed
Speedrun.com DR API
1 parent e3b1144 commit 7d0bd63

File tree

9 files changed

+106
-0
lines changed

9 files changed

+106
-0
lines changed

src/main/java/pw/roccodev/beezig/hiveapi/wrapper/player/games/DrStats.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
import pw.roccodev.beezig.hiveapi.wrapper.monthly.maxthat.dr.DrMonthlyProfile;
66
import pw.roccodev.beezig.hiveapi.wrapper.player.PvPStats;
77
import pw.roccodev.beezig.hiveapi.wrapper.player.Titleable;
8+
import pw.roccodev.beezig.hiveapi.wrapper.speedrun.WorldRecord;
89
import pw.roccodev.beezig.hiveapi.wrapper.utils.download.UrlBuilder;
910
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.LazyObject;
1011

12+
import java.util.Map;
13+
1114
public class DrStats extends PvPStats implements MonthliesReady, Titleable {
1215

1316
private LazyObject source;
@@ -22,6 +25,10 @@ public DrStats(String username, boolean convertToUUID) {
2225
source = getSource();
2326
}
2427

28+
public static WorldRecord getWorldRecord(String mapSpeedrunId) {
29+
return new WorldRecord(new LazyObject(null, new UrlBuilder().speedrun().level(mapSpeedrunId).build()));
30+
}
31+
2532
public long getTrapsActivated() {
2633
return source.getLong("trapsactivated");
2734
}
@@ -50,6 +57,26 @@ public Visibility getSelectedVisibility() {
5057
return Visibility.valueOf(source.getString("visibility"));
5158
}
5259

60+
public Map<String, Long> getMapRecords() {
61+
return source.getJSONObject("maprecords");
62+
}
63+
64+
public Map<String, Long> getMapKills() {
65+
return source.getJSONObject("mapkills");
66+
}
67+
68+
public Map<String, Long> getMapDeaths() {
69+
return source.getJSONObject("mapdeaths");
70+
}
71+
72+
public Map<String, Long> getTrapClassKills() {
73+
return source.getJSONObject("trapclasskills");
74+
}
75+
76+
public Map<String, Long> getTrapClassDeaths() {
77+
return source.getJSONObject("trapclassdeaths");
78+
}
79+
5380
@Override
5481
public DrMonthlyProfile getMonthlyProfile() {
5582
return getMonthlyProfile(getUUID());
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package pw.roccodev.beezig.hiveapi.wrapper.speedrun;
2+
3+
import pw.roccodev.beezig.hiveapi.wrapper.utils.download.UrlBuilder;
4+
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.JObject;
5+
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.LazyObject;
6+
7+
public class WorldRecord {
8+
9+
private LazyObject wrData;
10+
private JObject run;
11+
12+
private LazyObject holderData;
13+
14+
public WorldRecord(LazyObject wrData) {
15+
this.wrData = wrData;
16+
run = wrData.getJObject("data").getJArray("runs").getJObject(0).getJObject("run");
17+
}
18+
19+
public double getTime() {
20+
return run.getJObject("times").getDouble("primary_t");
21+
}
22+
23+
public String getHolderId() {
24+
return run.getJArray("players").getJObject(0).getString("id");
25+
}
26+
27+
public String getHolderName() {
28+
if(holderData == null) {
29+
holderData = new LazyObject(null, new UrlBuilder().speedrun().user(getHolderId()).build());
30+
}
31+
return holderData.getJObject("data").getJObject("names").getString("international");
32+
}
33+
34+
35+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package pw.roccodev.beezig.hiveapi.wrapper.utils.download;
2+
3+
public class SpeedrunUrlBuilder extends UrlBuilder {
4+
5+
SpeedrunUrlBuilder(UrlBuilder parent) {
6+
builder = parent.builder.append(URLs.SPEEDRUN_BASE);
7+
}
8+
9+
public SpeedrunUrlBuilder level(String id) {
10+
builder.append("leaderboards/369ep8dl/level/").append(id).append("/824xzvmd?top=1");
11+
return this;
12+
}
13+
14+
public SpeedrunUrlBuilder user(String id) {
15+
builder.append("users/").append(id);
16+
return this;
17+
}
18+
19+
}

src/main/java/pw/roccodev/beezig/hiveapi/wrapper/utils/download/URLs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
class URLs {
44

55
static final String HIVE_BASE = "api.hivemc.com/v1/";
6+
static final String SPEEDRUN_BASE = "www.speedrun.com/api/v1/";
67

78
static final String PLAYER_ENDPOINT = "player/";
89
static final String GAME_ENDPOINT = "game/";

src/main/java/pw/roccodev/beezig/hiveapi/wrapper/utils/download/UrlBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public UrlBuilder mojang(String username) {
2424
return this;
2525
}
2626

27+
public SpeedrunUrlBuilder speedrun() {
28+
return new SpeedrunUrlBuilder(this);
29+
}
30+
2731
public URL build() {
2832
try {
2933
return new URL(builder.toString().trim());

src/main/java/pw/roccodev/beezig/hiveapi/wrapper/utils/json/JArray.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public boolean getBoolean(int index) {
4343
return (boolean) jsonInput.get(index);
4444
}
4545

46+
public double getDouble(int index) {
47+
return (double) jsonInput.get(index);
48+
}
49+
4650
public JSONArray getInput() {
4751
return jsonInput;
4852
}

src/main/java/pw/roccodev/beezig/hiveapi/wrapper/utils/json/JObject.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public boolean getBoolean(String key) {
4343
return (boolean) jsonInput.get(key);
4444
}
4545

46+
public double getDouble(String key) {
47+
return (double) jsonInput.get(key);
48+
}
49+
4650
public JSONObject getInput() {
4751
return jsonInput;
4852
}

src/main/java/pw/roccodev/beezig/hiveapi/wrapper/utils/json/LazyArray.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ public boolean getBoolean(int index) {
6868
return super.getBoolean(index);
6969
}
7070

71+
@Override
72+
public double getDouble(int index) {
73+
checkIfSourceExists();
74+
return super.getDouble(index);
75+
}
76+
7177
public void fetch() {
7278
checkIfSourceExists();
7379
}

src/main/java/pw/roccodev/beezig/hiveapi/wrapper/utils/json/LazyObject.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ public boolean getBoolean(String key) {
6868
return super.getBoolean(key);
6969
}
7070

71+
@Override
72+
public double getDouble(String key) {
73+
checkIfSourceExists();
74+
return super.getDouble(key);
75+
}
76+
7177
public void fetch() {
7278
checkIfSourceExists();
7379
}

0 commit comments

Comments
 (0)