Skip to content

Commit 968839b

Browse files
authored
Bring Java API up to date with REST API (#250)
* Removed session endpoint accessors * Added recentGames to java api
1 parent 8a0913a commit 968839b

File tree

5 files changed

+99
-101
lines changed

5 files changed

+99
-101
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.hypixel.example;
2+
3+
public class GetRecentGamesExample {
4+
5+
public static void main(String[] args) {
6+
ExampleUtil.API.getRecentGames(ExampleUtil.HYPIXEL).whenComplete(ExampleUtil.getTestConsumer());
7+
ExampleUtil.await();
8+
}
9+
}

Example/src/main/java/net/hypixel/example/GetSessionExample.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

Java/src/main/java/net/hypixel/api/HypixelAPI.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,6 @@ public CompletableFuture<PlayerCountReply> getPlayerCount() {
8282
return get(PlayerCountReply.class, "playerCount");
8383
}
8484

85-
/**
86-
* Session endpoint is bound to be removed at some point,
87-
* data is mainly internal and highly inaccurate for online checking
88-
*/
89-
@Deprecated
90-
public CompletableFuture<SessionReply> getSessionByUuid(UUID player) {
91-
return get(SessionReply.class, "session", "uuid", player);
92-
}
93-
94-
/**
95-
* Session endpoint is bound to be removed at some point,
96-
* data is mainly internal and highly inaccurate for online checking
97-
*/
98-
@Deprecated
99-
public CompletableFuture<SessionReply> getSessionByUuid(String player) {
100-
return get(SessionReply.class, "session", "uuid", player);
101-
}
102-
10385
public CompletableFuture<PlayerReply> getPlayerByUuid(UUID player) {
10486
return get(PlayerReply.class, "player", "uuid", player);
10587
}
@@ -209,6 +191,15 @@ public CompletableFuture<StatusReply> getStatus(UUID uuid) {
209191
return get(StatusReply.class, "status", "uuid", uuid);
210192
}
211193

194+
/**
195+
* Gets up to 100 of the player's most recently played games. Games are removed from this list after 3 days.
196+
* @param uuid of player
197+
* @return CompletableFuture with recentGames reply
198+
*/
199+
public CompletableFuture<RecentGamesReply> getRecentGames(UUID uuid) {
200+
return get(RecentGamesReply.class, "recentGames", "uuid", uuid);
201+
}
202+
212203
/**
213204
* Retrieve resources which don't change often.
214205
*
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package net.hypixel.api.reply;
2+
3+
import java.time.ZonedDateTime;
4+
import java.util.List;
5+
import net.hypixel.api.util.GameType;
6+
7+
public class RecentGamesReply extends AbstractReply {
8+
9+
private List<GameSession> games;
10+
11+
/**
12+
* @return Up to 100 of the player's most recently played games
13+
* @see GameSession
14+
*/
15+
public List<GameSession> getGames() {
16+
return games;
17+
}
18+
19+
@Override
20+
public String toString() {
21+
return "RecentGamesReply{" +
22+
"games=" + games +
23+
'}';
24+
}
25+
26+
public static class GameSession {
27+
28+
private ZonedDateTime date;
29+
private GameType gameType;
30+
private String mode;
31+
private String map;
32+
private ZonedDateTime ended;
33+
34+
/**
35+
* @return When the game started
36+
*/
37+
public ZonedDateTime getStartDate() {
38+
return date;
39+
}
40+
41+
/**
42+
* @return Game played during this session
43+
* @see net.hypixel.api.util.GameType
44+
*/
45+
public GameType getGameType() {
46+
return gameType;
47+
}
48+
49+
/**
50+
* @return Subtype of the game played (e.g. "solo_insane_lucky" for {@link GameType#SKYWARS})
51+
*/
52+
public String getMode() {
53+
return mode;
54+
}
55+
56+
/**
57+
* @return Map that was played on
58+
*/
59+
public String getMap() {
60+
return map;
61+
}
62+
63+
/**
64+
* @return When the game ended. If null, the game is ongoing
65+
*/
66+
public ZonedDateTime getEndDate() {
67+
return ended;
68+
}
69+
70+
@Override
71+
public String toString() {
72+
return "GameSession{" +
73+
"date=" + date +
74+
", gameType=" + gameType +
75+
", mode='" + mode + '\'' +
76+
", map='" + map + '\'' +
77+
", ended=" + ended +
78+
'}';
79+
}
80+
}
81+
}

Java/src/main/java/net/hypixel/api/reply/SessionReply.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)