From 9961ed33630812976b6e3669d9b730809c062b05 Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Mon, 26 Jun 2023 10:49:12 +0100 Subject: [PATCH] Implement support for SkyBlock fire sales (#601) --- .../main/java/net/hypixel/api/HypixelAPI.java | 59 +++++++++++-------- .../skyblock/firesales/FireSaleItem.java | 45 ++++++++++++++ .../firesales/SkyBlockFireSalesReply.java | 20 +++++++ ...nsExample.java => GetAuctionsExample.java} | 2 +- ...aExample.java => GetBingoDataExample.java} | 2 +- .../example/skyblock/GetFireSalesExample.java | 10 ++++ ...ckNewsExample.java => GetNewsExample.java} | 2 +- ...ileExample.java => GetProfileExample.java} | 2 +- ...esExample.java => GetProfilesExample.java} | 2 +- 9 files changed, 113 insertions(+), 31 deletions(-) create mode 100644 hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/firesales/FireSaleItem.java create mode 100644 hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/firesales/SkyBlockFireSalesReply.java rename hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/{GetSkyBlockAuctionsExample.java => GetAuctionsExample.java} (94%) rename hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/{GetSkyBlockBingoDataExample.java => GetBingoDataExample.java} (86%) create mode 100644 hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetFireSalesExample.java rename hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/{GetSkyBlockNewsExample.java => GetNewsExample.java} (87%) rename hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/{GetSkyBlockProfileExample.java => GetProfileExample.java} (98%) rename hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/{GetSkyBlockProfilesExample.java => GetProfilesExample.java} (86%) diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java b/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java index b466b885..570aab45 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java @@ -12,6 +12,7 @@ import net.hypixel.api.reply.*; import net.hypixel.api.reply.skyblock.*; import net.hypixel.api.reply.skyblock.bingo.SkyBlockBingoDataReply; +import net.hypixel.api.reply.skyblock.firesales.SkyBlockFireSalesReply; import net.hypixel.api.util.PropertyFilter; import net.hypixel.api.util.ResourceType; import net.hypixel.api.util.Utilities; @@ -39,15 +40,15 @@ public void shutdown() { } public CompletableFuture getBoosters() { - return get(BoostersReply.class, "boosters"); + return get(true, BoostersReply.class, "boosters"); } public CompletableFuture getLeaderboards() { - return get(LeaderboardsReply.class, "leaderboards"); + return get(true, LeaderboardsReply.class, "leaderboards"); } public CompletableFuture getPunishmentStats() { - return get(PunishmentStatsReply.class, "punishmentstats"); + return get(true, PunishmentStatsReply.class, "punishmentstats"); } /** @@ -55,7 +56,7 @@ public CompletableFuture getPunishmentStats() { * @return {@link CompletableFuture} containing {@link PlayerReply} */ public CompletableFuture getPlayerByUuid(UUID player) { - return get(PlayerReply.class, "player", + return get(true, PlayerReply.class, "player", HTTPQueryParams.create() .add("uuid", player) ); @@ -66,7 +67,7 @@ public CompletableFuture getPlayerByUuid(UUID player) { * @return {@link CompletableFuture} containing {@link PlayerReply} */ public CompletableFuture getPlayerByUuid(String player) { - return get(PlayerReply.class, "player", + return get(true, PlayerReply.class, "player", HTTPQueryParams.create() .add("uuid", player) ); @@ -106,7 +107,7 @@ public CompletableFuture getPlayerByName(String player, PropertyFil */ @Deprecated public CompletableFuture getPlayerByName(String player) { - return get(PlayerReply.class, "player", + return get(true, PlayerReply.class, "player", HTTPQueryParams.create() .add("name", player) ); @@ -117,7 +118,7 @@ public CompletableFuture getPlayerByName(String player) { * @return {@link CompletableFuture} containing {@link GuildReply} */ public CompletableFuture getGuildByPlayer(UUID player) { - return get(GuildReply.class, "guild", + return get(true, GuildReply.class, "guild", HTTPQueryParams.create() .add("player", player) ); @@ -128,7 +129,7 @@ public CompletableFuture getGuildByPlayer(UUID player) { * @return {@link CompletableFuture} containing {@link GuildReply} */ public CompletableFuture getGuildByPlayer(String player) { - return get(GuildReply.class, "guild", + return get(true, GuildReply.class, "guild", HTTPQueryParams.create() .add("player", player) ); @@ -139,7 +140,7 @@ public CompletableFuture getGuildByPlayer(String player) { * @return {@link CompletableFuture} containing {@link GuildReply} */ public CompletableFuture getGuildByName(String name) { - return get(GuildReply.class, "guild", + return get(true, GuildReply.class, "guild", HTTPQueryParams.create() .add("name", name) ); @@ -150,7 +151,7 @@ public CompletableFuture getGuildByName(String name) { * @return {@link CompletableFuture} containing {@link GuildReply} */ public CompletableFuture getGuildById(String id) { - return get(GuildReply.class, "guild", + return get(true, GuildReply.class, "guild", HTTPQueryParams.create() .add("id", id) ); @@ -161,11 +162,11 @@ public CompletableFuture getGuildById(String id) { */ @Deprecated public CompletableFuture getKey() { - return get(KeyReply.class, "key"); + return get(true, KeyReply.class, "key"); } public CompletableFuture getCounts() { - return get(CountsReply.class, "counts"); + return get(true, CountsReply.class, "counts"); } /** @@ -177,7 +178,7 @@ public CompletableFuture getCounts() { * @return {@link CompletableFuture} containing {@link StatusReply} */ public CompletableFuture getStatus(UUID uuid) { - return get(StatusReply.class, "status", + return get(true, StatusReply.class, "status", HTTPQueryParams.create() .add("uuid", uuid) ); @@ -190,7 +191,7 @@ public CompletableFuture getStatus(UUID uuid) { * @return {@link CompletableFuture} containing {@link RecentGamesReply} */ public CompletableFuture getRecentGames(UUID uuid) { - return get(RecentGamesReply.class, "recentGames", + return get(true, RecentGamesReply.class, "recentGames", HTTPQueryParams.create() .add("uuid", uuid) ); @@ -216,7 +217,7 @@ public CompletableFuture getPetRepository() { } public CompletableFuture getSkyBlockProfile(String profile) { - return get(SkyBlockProfileReply.class, "skyblock/profile", + return get(true, SkyBlockProfileReply.class, "skyblock/profile", HTTPQueryParams.create() .add("profile", profile) ); @@ -227,7 +228,7 @@ public CompletableFuture getSkyBlockProfile(String profile * @return the future */ public CompletableFuture getSkyBlockProfiles(UUID player) { - return get(SkyBlockProfilesReply.class, "skyblock/profiles", + return get(true, SkyBlockProfilesReply.class, "skyblock/profiles", HTTPQueryParams.create() .add("uuid", player) ); @@ -238,7 +239,7 @@ public CompletableFuture getSkyBlockProfiles(UUID player) * @return the future */ public CompletableFuture getSkyBlockProfiles(String player) { - return get(SkyBlockProfilesReply.class, "skyblock/profiles", + return get(true, SkyBlockProfilesReply.class, "skyblock/profiles", HTTPQueryParams.create() .add("uuid", player) ); @@ -251,7 +252,7 @@ public CompletableFuture getSkyBlockProfiles(String playe * @return CompletableFuture containing a {@link SkyBlockBingoDataReply} */ public CompletableFuture getSkyblockBingoData(UUID player) { - return get(SkyBlockBingoDataReply.class, "skyblock/bingo", + return get(true, SkyBlockBingoDataReply.class, "skyblock/bingo", HTTPQueryParams.create() .add("uuid", player) ); @@ -264,18 +265,18 @@ public CompletableFuture getSkyblockBingoData(UUID playe * @return CompletableFuture containing a {@link SkyBlockBingoDataReply} */ public CompletableFuture getSkyblockBingoData(String player) { - return get(SkyBlockBingoDataReply.class, "skyblock/bingo", + return get(true, SkyBlockBingoDataReply.class, "skyblock/bingo", HTTPQueryParams.create() .add("uuid", player) ); } public CompletableFuture getSkyBlockNews() { - return get(SkyBlockNewsReply.class, "skyblock/news"); + return get(true, SkyBlockNewsReply.class, "skyblock/news"); } public CompletableFuture getSkyBlockAuctions(int page) { - return get(SkyBlockAuctionsReply.class, "skyblock/auctions", + return get(false, SkyBlockAuctionsReply.class, "skyblock/auctions", HTTPQueryParams.create() .add("page", page) ); @@ -287,7 +288,11 @@ public CompletableFuture getSkyBlockAuctions(int page) { * @return {@link CompletableFuture} containing {@link SkyBlockBazaarReply} */ public CompletableFuture getSkyBlockBazaar() { - return get(SkyBlockBazaarReply.class, "skyblock/bazaar"); + return get(false, SkyBlockBazaarReply.class, "skyblock/bazaar"); + } + + public CompletableFuture getSkyBlockFireSales() { + return get(false, SkyBlockFireSalesReply.class, "skyblock/firesales"); } /** @@ -300,16 +305,18 @@ private CompletableFuture applyFilterFuture(CompletableFuture CompletableFuture get(Class clazz, String request) { - return get(clazz, request, null); + private CompletableFuture get(boolean authenticated, Class clazz, String request) { + return get(authenticated, clazz, request, null); } - private CompletableFuture get(Class clazz, String request, HTTPQueryParams params) { + private CompletableFuture get(boolean authenticated, Class clazz, String request, HTTPQueryParams params) { String url = BASE_URL + request; if (params != null) { url = params.getAsQueryString(url); } - return httpClient.makeAuthenticatedRequest(url) + + CompletableFuture future = authenticated ? httpClient.makeAuthenticatedRequest(url) : httpClient.makeRequest(url); + return future .thenApply(this::checkResponse) .thenApply(response -> { if (clazz == ResourceReply.class) { diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/firesales/FireSaleItem.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/firesales/FireSaleItem.java new file mode 100644 index 00000000..524ccc91 --- /dev/null +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/firesales/FireSaleItem.java @@ -0,0 +1,45 @@ +package net.hypixel.api.reply.skyblock.firesales; + +import com.google.gson.annotations.SerializedName; + +import java.time.ZonedDateTime; + +public class FireSaleItem { + @SerializedName("item_id") + private String itemId; + private ZonedDateTime start; + private ZonedDateTime end; + private int amount; + private int price; + + public String getItemId() { + return itemId; + } + + public ZonedDateTime getStart() { + return start; + } + + public ZonedDateTime getEnd() { + return end; + } + + public int getAmount() { + return amount; + } + + public int getPrice() { + return price; + } + + @Override + public String toString() { + return "FireSaleItem{" + + "itemId='" + itemId + '\'' + + ", start=" + start + + ", end=" + end + + ", amount=" + amount + + ", price=" + price + + '}'; + } +} diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/firesales/SkyBlockFireSalesReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/firesales/SkyBlockFireSalesReply.java new file mode 100644 index 00000000..acbde4d9 --- /dev/null +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/skyblock/firesales/SkyBlockFireSalesReply.java @@ -0,0 +1,20 @@ +package net.hypixel.api.reply.skyblock.firesales; + +import net.hypixel.api.reply.AbstractReply; + +import java.util.List; + +public class SkyBlockFireSalesReply extends AbstractReply { + private List sales; + + public List getSales() { + return sales; + } + + @Override + public String toString() { + return "SkyBlockFireSalesReply{" + + "sales=" + sales + + "} " + super.toString(); + } +} diff --git a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockAuctionsExample.java b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetAuctionsExample.java similarity index 94% rename from hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockAuctionsExample.java rename to hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetAuctionsExample.java index 789af16c..3aa0ec81 100644 --- a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockAuctionsExample.java +++ b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetAuctionsExample.java @@ -2,7 +2,7 @@ import net.hypixel.api.example.ExampleUtil; -public class GetSkyBlockAuctionsExample { +public class GetAuctionsExample { public static void main(String[] args) { ExampleUtil.API.getSkyBlockAuctions(0).whenComplete((page0, throwable) -> { if (throwable != null) { diff --git a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockBingoDataExample.java b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetBingoDataExample.java similarity index 86% rename from hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockBingoDataExample.java rename to hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetBingoDataExample.java index a9395217..a36dc278 100644 --- a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockBingoDataExample.java +++ b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetBingoDataExample.java @@ -2,7 +2,7 @@ import net.hypixel.api.example.ExampleUtil; -public class GetSkyBlockBingoDataExample { +public class GetBingoDataExample { public static void main(String[] args) { ExampleUtil.API.getSkyblockBingoData(ExampleUtil.HYPIXEL).whenComplete(ExampleUtil.getTestConsumer()); ExampleUtil.await(); diff --git a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetFireSalesExample.java b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetFireSalesExample.java new file mode 100644 index 00000000..87d9efd2 --- /dev/null +++ b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetFireSalesExample.java @@ -0,0 +1,10 @@ +package net.hypixel.api.example.skyblock; + +import net.hypixel.api.example.ExampleUtil; + +public class GetFireSalesExample { + public static void main(String[] args) { + ExampleUtil.API.getSkyBlockFireSales().whenComplete(ExampleUtil.getTestConsumer()); + ExampleUtil.await(); + } +} diff --git a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockNewsExample.java b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetNewsExample.java similarity index 87% rename from hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockNewsExample.java rename to hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetNewsExample.java index 11c77b99..a63ed1a6 100644 --- a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockNewsExample.java +++ b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetNewsExample.java @@ -2,7 +2,7 @@ import net.hypixel.api.example.ExampleUtil; -public class GetSkyBlockNewsExample { +public class GetNewsExample { public static void main(String[] args) { ExampleUtil.API.getSkyBlockNews().whenComplete(ExampleUtil.getTestConsumer()); ExampleUtil.await(); diff --git a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockProfileExample.java b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetProfileExample.java similarity index 98% rename from hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockProfileExample.java rename to hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetProfileExample.java index 54913e4f..65f95504 100644 --- a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockProfileExample.java +++ b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetProfileExample.java @@ -9,7 +9,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; -public class GetSkyBlockProfileExample { +public class GetProfileExample { public static void main(String[] args) { ExampleUtil.API.getPlayerByUuid(ExampleUtil.HYPIXEL).whenComplete((reply, error) -> { diff --git a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockProfilesExample.java b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetProfilesExample.java similarity index 86% rename from hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockProfilesExample.java rename to hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetProfilesExample.java index feecad85..2bf49ed2 100644 --- a/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetSkyBlockProfilesExample.java +++ b/hypixel-api-example/src/main/java/net/hypixel/api/example/skyblock/GetProfilesExample.java @@ -2,7 +2,7 @@ import net.hypixel.api.example.ExampleUtil; -public class GetSkyBlockProfilesExample { +public class GetProfilesExample { public static void main(String[] args) { ExampleUtil.API.getSkyBlockProfiles(ExampleUtil.HYPIXEL).whenComplete(ExampleUtil.getTestConsumer()); ExampleUtil.await();