diff --git a/Example/src/main/java/net/hypixel/example/GetRecentGamesExample.java b/Example/src/main/java/net/hypixel/example/GetRecentGamesExample.java new file mode 100644 index 00000000..62fbcc07 --- /dev/null +++ b/Example/src/main/java/net/hypixel/example/GetRecentGamesExample.java @@ -0,0 +1,9 @@ +package net.hypixel.example; + +public class GetRecentGamesExample { + + public static void main(String[] args) { + ExampleUtil.API.getRecentGames(ExampleUtil.HYPIXEL).whenComplete(ExampleUtil.getTestConsumer()); + ExampleUtil.await(); + } +} diff --git a/Example/src/main/java/net/hypixel/example/GetSessionExample.java b/Example/src/main/java/net/hypixel/example/GetSessionExample.java deleted file mode 100644 index a40da2cd..00000000 --- a/Example/src/main/java/net/hypixel/example/GetSessionExample.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.hypixel.example; - -public class GetSessionExample { - public static void main(String[] args) { - // this will always be null because hypixel is staff account - // see comment in SessionReply - ExampleUtil.API.getSessionByUuid(ExampleUtil.HYPIXEL).whenComplete(ExampleUtil.getTestConsumer()); - ExampleUtil.await(); - } -} diff --git a/Java/src/main/java/net/hypixel/api/HypixelAPI.java b/Java/src/main/java/net/hypixel/api/HypixelAPI.java index 73cfbdd8..bb5835a9 100644 --- a/Java/src/main/java/net/hypixel/api/HypixelAPI.java +++ b/Java/src/main/java/net/hypixel/api/HypixelAPI.java @@ -82,24 +82,6 @@ public CompletableFuture getPlayerCount() { return get(PlayerCountReply.class, "playerCount"); } - /** - * Session endpoint is bound to be removed at some point, - * data is mainly internal and highly inaccurate for online checking - */ - @Deprecated - public CompletableFuture getSessionByUuid(UUID player) { - return get(SessionReply.class, "session", "uuid", player); - } - - /** - * Session endpoint is bound to be removed at some point, - * data is mainly internal and highly inaccurate for online checking - */ - @Deprecated - public CompletableFuture getSessionByUuid(String player) { - return get(SessionReply.class, "session", "uuid", player); - } - public CompletableFuture getPlayerByUuid(UUID player) { return get(PlayerReply.class, "player", "uuid", player); } @@ -209,6 +191,15 @@ public CompletableFuture getStatus(UUID uuid) { return get(StatusReply.class, "status", "uuid", uuid); } + /** + * Gets up to 100 of the player's most recently played games. Games are removed from this list after 3 days. + * @param uuid of player + * @return CompletableFuture with recentGames reply + */ + public CompletableFuture getRecentGames(UUID uuid) { + return get(RecentGamesReply.class, "recentGames", "uuid", uuid); + } + /** * Retrieve resources which don't change often. * diff --git a/Java/src/main/java/net/hypixel/api/reply/RecentGamesReply.java b/Java/src/main/java/net/hypixel/api/reply/RecentGamesReply.java new file mode 100644 index 00000000..5c4a82ee --- /dev/null +++ b/Java/src/main/java/net/hypixel/api/reply/RecentGamesReply.java @@ -0,0 +1,81 @@ +package net.hypixel.api.reply; + +import java.time.ZonedDateTime; +import java.util.List; +import net.hypixel.api.util.GameType; + +public class RecentGamesReply extends AbstractReply { + + private List games; + + /** + * @return Up to 100 of the player's most recently played games + * @see GameSession + */ + public List getGames() { + return games; + } + + @Override + public String toString() { + return "RecentGamesReply{" + + "games=" + games + + '}'; + } + + public static class GameSession { + + private ZonedDateTime date; + private GameType gameType; + private String mode; + private String map; + private ZonedDateTime ended; + + /** + * @return When the game started + */ + public ZonedDateTime getStartDate() { + return date; + } + + /** + * @return Game played during this session + * @see net.hypixel.api.util.GameType + */ + public GameType getGameType() { + return gameType; + } + + /** + * @return Subtype of the game played (e.g. "solo_insane_lucky" for {@link GameType#SKYWARS}) + */ + public String getMode() { + return mode; + } + + /** + * @return Map that was played on + */ + public String getMap() { + return map; + } + + /** + * @return When the game ended. If null, the game is ongoing + */ + public ZonedDateTime getEndDate() { + return ended; + } + + @Override + public String toString() { + return "GameSession{" + + "date=" + date + + ", gameType=" + gameType + + ", mode='" + mode + '\'' + + ", map='" + map + '\'' + + ", ended=" + ended + + '}'; + } + } +} diff --git a/Java/src/main/java/net/hypixel/api/reply/SessionReply.java b/Java/src/main/java/net/hypixel/api/reply/SessionReply.java deleted file mode 100644 index 8e681f13..00000000 --- a/Java/src/main/java/net/hypixel/api/reply/SessionReply.java +++ /dev/null @@ -1,73 +0,0 @@ -package net.hypixel.api.reply; - -import net.hypixel.api.util.GameType; - -import java.util.Set; -import java.util.UUID; - -/** - * This method is deprecated and will be removed soon. - */ -@Deprecated -public class SessionReply extends AbstractReply { - private Session session; - - /** - * Session can be null if - * 1) The player is in a lobby or offline - * 2) The player has a staff rank - * - * @return The session, or null if either of above reasons is met - */ - public Session getSession() { - return session; - } - - @Override - public String toString() { - return "SessionReply{" + - "session=" + session + - "} " + super.toString(); - } - - public class Session { - /** - * GameType could be null if a new game has been released - * and GameType is not yet added to {@link GameType}. - *

- * This will NOT throw an exception. - */ - private GameType gameType; - /** - * Server name for session - */ - private String server; - /** - * Set of UUIDs of players currently in this session - */ - private Set players; - - public GameType getGameType() { - return gameType; - } - - @Deprecated - public String getServer() { - return server; - } - - @Deprecated - public Set getPlayers() { - return players; - } - - @Override - public String toString() { - return "Session{" + - "gameType=" + gameType + - ", server='" + server + '\'' + - ", players=" + players + - '}'; - } - } -}