diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..3ee30a88 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.java] +ij_java_imports_layout = *,|,javax.**,java.**,|,$* + +ij_java_use_single_class_imports = true + +ij_java_class_count_to_use_import_on_demand = 999999999 +ij_java_names_count_to_use_import_on_demand = 999999999 diff --git a/.gitignore b/.gitignore index c1a7f5a1..010ca706 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ target Example/target Website/javadocs +hypixel-api-example/src/main/resources/config.properties 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 942cf1b9..98b14d4c 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 @@ -9,8 +9,22 @@ import net.hypixel.api.http.HypixelHttpResponse; import net.hypixel.api.pets.IPetRepository; import net.hypixel.api.pets.impl.PetRepositoryImpl; -import net.hypixel.api.reply.*; -import net.hypixel.api.reply.skyblock.*; +import net.hypixel.api.reply.AbstractReply; +import net.hypixel.api.reply.BoostersReply; +import net.hypixel.api.reply.CountsReply; +import net.hypixel.api.reply.GuildReply; +import net.hypixel.api.reply.LeaderboardsReply; +import net.hypixel.api.reply.PlayerReply; +import net.hypixel.api.reply.PunishmentStatsReply; +import net.hypixel.api.reply.RateLimitedReply; +import net.hypixel.api.reply.RecentGamesReply; +import net.hypixel.api.reply.ResourceReply; +import net.hypixel.api.reply.StatusReply; +import net.hypixel.api.reply.skyblock.SkyBlockAuctionsReply; +import net.hypixel.api.reply.skyblock.SkyBlockBazaarReply; +import net.hypixel.api.reply.skyblock.SkyBlockNewsReply; +import net.hypixel.api.reply.skyblock.SkyBlockProfileReply; +import net.hypixel.api.reply.skyblock.SkyBlockProfilesReply; import net.hypixel.api.reply.skyblock.bingo.SkyBlockBingoDataReply; import net.hypixel.api.reply.skyblock.firesales.SkyBlockFireSalesReply; import net.hypixel.api.util.PropertyFilter; diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/adapters/DateTimeTypeAdapter.java b/hypixel-api-core/src/main/java/net/hypixel/api/adapters/DateTimeTypeAdapter.java index 849f636b..800a602d 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/adapters/DateTimeTypeAdapter.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/adapters/DateTimeTypeAdapter.java @@ -1,6 +1,12 @@ package net.hypixel.api.adapters; -import com.google.gson.*; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; import net.hypixel.api.util.Utilities; import java.lang.reflect.Type; diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/adapters/GameTypeTypeAdapter.java b/hypixel-api-core/src/main/java/net/hypixel/api/adapters/GameTypeTypeAdapter.java index 2ef87dd7..feaacb31 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/adapters/GameTypeTypeAdapter.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/adapters/GameTypeTypeAdapter.java @@ -1,6 +1,12 @@ package net.hypixel.api.adapters; -import com.google.gson.*; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; import net.hypixel.api.data.type.GameType; import java.lang.reflect.Type; diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/adapters/ServerTypeTypeAdapter.java b/hypixel-api-core/src/main/java/net/hypixel/api/adapters/ServerTypeTypeAdapter.java index ea89251e..0de7c11c 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/adapters/ServerTypeTypeAdapter.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/adapters/ServerTypeTypeAdapter.java @@ -1,6 +1,12 @@ package net.hypixel.api.adapters; -import com.google.gson.*; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; import net.hypixel.api.data.type.GameType; import net.hypixel.api.data.type.ServerType; diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/adapters/UUIDTypeAdapter.java b/hypixel-api-core/src/main/java/net/hypixel/api/adapters/UUIDTypeAdapter.java index 609e49f5..d396b1b4 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/adapters/UUIDTypeAdapter.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/adapters/UUIDTypeAdapter.java @@ -1,6 +1,12 @@ package net.hypixel.api.adapters; -import com.google.gson.*; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; import net.hypixel.api.util.Utilities; import java.lang.reflect.Type; diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/data/type/ServerType.java b/hypixel-api-core/src/main/java/net/hypixel/api/data/type/ServerType.java index aa73aa21..3c95e7f2 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/data/type/ServerType.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/data/type/ServerType.java @@ -2,10 +2,6 @@ public interface ServerType { - String name(); - - String getName(); - static ServerType valueOf(String value) { try { return GameType.valueOf(value); @@ -22,4 +18,8 @@ static ServerType valueOf(String value) { return null; } + String name(); + + String getName(); + } diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/http/HTTPQueryParams.java b/hypixel-api-core/src/main/java/net/hypixel/api/http/HTTPQueryParams.java index 3f64ad2e..46bc56e1 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/http/HTTPQueryParams.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/http/HTTPQueryParams.java @@ -5,16 +5,16 @@ public class HTTPQueryParams { - public static HTTPQueryParams create() { - return new HTTPQueryParams(); - } - private final Map params = new HashMap<>(); private HTTPQueryParams() { } + public static HTTPQueryParams create() { + return new HTTPQueryParams(); + } + public HTTPQueryParams add(String key, Object value) { this.params.put(key, value); return this; diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/pets/IPetRepository.java b/hypixel-api-core/src/main/java/net/hypixel/api/pets/IPetRepository.java index 4212204b..00c8b187 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/pets/IPetRepository.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/pets/IPetRepository.java @@ -46,7 +46,7 @@ public interface IPetRepository { /** * Gets if a player has unlocked the specified {@link IPetType} * - * @param type the pet type the player must have + * @param type the pet type the player must have * @param player the player to check against * @return {@code true} if the player has unlocked the pet, otherwise {@code false} */ diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/pets/PetStats.java b/hypixel-api-core/src/main/java/net/hypixel/api/pets/PetStats.java index 18bd43e3..1f6a21f6 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/pets/PetStats.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/pets/PetStats.java @@ -30,7 +30,7 @@ public PetStats(IPetRepository petRepository, Map> p * * Note: If this returns {@code null}, it doesn't mean that the player hasn't unlocked the pet. * What it does mean though, is that the player hasn't given any attributes nor a name to the pet - * + *

* To check if a player has unlocked a pet, use {@link IPetRepository#hasPlayerUnlocked(IPetType, PlayerReply.Player)} * * @param type the pet type to retrieve diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/pets/PetType.java b/hypixel-api-core/src/main/java/net/hypixel/api/pets/PetType.java index 8ceead24..ed4c87df 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/pets/PetType.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/pets/PetType.java @@ -4,6 +4,7 @@ /** * The old and deprecated enum for the pet types + * * @deprecated Consider using the {@link IPetRepository} */ @Deprecated diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/CountsReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/CountsReply.java index 863a1314..8f0e0c7d 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/reply/CountsReply.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/CountsReply.java @@ -14,6 +14,14 @@ public int getPlayerCount() { return playerCount; } + @Override + public String toString() { + return "GameCountsReply{" + + "games=" + games + + ", playerCount=" + playerCount + + "} " + super.toString(); + } + public static class GameCount { private Map modes; private int players; @@ -34,12 +42,4 @@ public String toString() { '}'; } } - - @Override - public String toString() { - return "GameCountsReply{" + - "games=" + games + - ", playerCount=" + playerCount + - "} " + super.toString(); - } } diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/GuildReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/GuildReply.java index 05d554e1..81c5f4f7 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/reply/GuildReply.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/GuildReply.java @@ -8,7 +8,12 @@ import java.time.LocalDate; import java.time.ZonedDateTime; -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; // Suppressed because most fields are assigned by Gson via reflection. @SuppressWarnings({"unused", "RedundantSuppression", "MismatchedQueryAndUpdateOfCollection"}) @@ -23,8 +28,8 @@ public Guild getGuild() { @Override public String toString() { return "GuildReply{" + - "guild=" + guild + - "} " + super.toString(); + "guild=" + guild + + "} " + super.toString(); } public static class Guild { @@ -153,8 +158,8 @@ public Banner getBanner() { */ public List getMembers() { return members == null - ? Collections.emptyList() - : Collections.unmodifiableList(members); + ? Collections.emptyList() + : Collections.unmodifiableList(members); } /** @@ -174,8 +179,8 @@ public List getMembers() { */ public List getRanks() { return ranks == null - ? Collections.emptyList() - : Collections.unmodifiableList(ranks); + ? Collections.emptyList() + : Collections.unmodifiableList(ranks); } /** @@ -186,8 +191,8 @@ public List getRanks() { */ public List getPreferredGames() { return preferredGames == null - ? Collections.emptyList() - : Collections.unmodifiableList(preferredGames); + ? Collections.emptyList() + : Collections.unmodifiableList(preferredGames); } /** @@ -204,8 +209,8 @@ public long getExperienceForGame(GameType game) { } return Optional.ofNullable(guildExpByGameType) - .map(expByGame -> expByGame.get(game)) - .orElse(0L); + .map(expByGame -> expByGame.get(game)) + .orElse(0L); } /** @@ -221,8 +226,8 @@ public int getAchievementHighScore(GuildAchievement achievement) { throw new IllegalArgumentException("Cannot get high-score for null achievement"); } return Optional.ofNullable(achievements) - .map(highScores -> highScores.get(achievement)) - .orElse(0); + .map(highScores -> highScores.get(achievement)) + .orElse(0); } /** @@ -316,29 +321,29 @@ public int getCoinsEver() { */ public int getLegacyRanking() { return Optional.ofNullable(legacyRanking) - .map(ranking -> ranking + 1) - .orElse(-1); + .map(ranking -> ranking + 1) + .orElse(-1); } @Override public String toString() { return "Guild{" + - "id='" + id + '\'' + - ", name='" + name + '\'' + - ", description='" + description + '\'' + - ", creationDate=" + creationDate + - ", tag='" + tag + '\'' + - ", tagColor='" + tagColor + '\'' + - ", banner=" + banner + - ", members=" + members + - ", ranks=" + ranks + - ", experience=" + experience + - ", isPubliclyListed=" + isPubliclyListed + - ", isJoinable=" + isJoinable + - ", coins=" + coins + - ", coinsEver=" + coinsEver + - ", legacyRanking=" + legacyRanking + - '}'; + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", description='" + description + '\'' + + ", creationDate=" + creationDate + + ", tag='" + tag + '\'' + + ", tagColor='" + tagColor + '\'' + + ", banner=" + banner + + ", members=" + members + + ", ranks=" + ranks + + ", experience=" + experience + + ", isPubliclyListed=" + isPubliclyListed + + ", isJoinable=" + isJoinable + + ", coins=" + coins + + ", coinsEver=" + coinsEver + + ", legacyRanking=" + legacyRanking + + '}'; } @Override @@ -414,8 +419,8 @@ public int getExperienceEarned(LocalDate date) { } return Optional.ofNullable(weeklyExperience) - .map(expByDate -> expByDate.get(date.toString())) - .orElse(-1); + .map(expByDate -> expByDate.get(date.toString())) + .orElse(-1); } /** @@ -429,10 +434,10 @@ public ZonedDateTime getJoined() { @Override public String toString() { return "Member{" + - "uuid=" + uuid + - ", rank='" + rank + '\'' + - ", joined=" + joinDate + - '}'; + "uuid=" + uuid + + ", rank='" + rank + '\'' + + ", joined=" + joinDate + + '}'; } @Override @@ -518,12 +523,12 @@ public int getPriority() { @Override public String toString() { return "Rank{" + - "name='" + name + '\'' + - ", tag='" + tag + '\'' + - ", isDefault=" + isDefault + - ", creationDate=" + creationDate + - ", priority=" + priority + - '}'; + "name='" + name + '\'' + + ", tag='" + tag + '\'' + + ", isDefault=" + isDefault + + ", creationDate=" + creationDate + + ", priority=" + priority + + '}'; } @Override @@ -536,7 +541,7 @@ public boolean equals(Object o) { } Rank rank = (Rank) o; return Objects.equals(name, rank.name) && - Objects.equals(creationDate, rank.creationDate); + Objects.equals(creationDate, rank.creationDate); } @Override diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/ResourceReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/ResourceReply.java index b36cc509..fb2b73b3 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/reply/ResourceReply.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/ResourceReply.java @@ -1,7 +1,6 @@ package net.hypixel.api.reply; import com.google.gson.JsonObject; -import net.hypixel.api.reply.AbstractReply; public class ResourceReply extends AbstractReply { diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/util/Banner.java b/hypixel-api-core/src/main/java/net/hypixel/api/util/Banner.java index f2c44324..a20c78d8 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/util/Banner.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/util/Banner.java @@ -1,6 +1,7 @@ package net.hypixel.api.util; import com.google.gson.annotations.SerializedName; + import java.util.Collections; import java.util.List; import java.util.Objects; @@ -70,17 +71,12 @@ public String getBase() { * @return an immutable list of the banner's layers. */ public List getPatterns() { - return patterns == null - ? Collections.emptyList() - : Collections.unmodifiableList(patterns); + return patterns == null ? Collections.emptyList() : Collections.unmodifiableList(patterns); } @Override public String toString() { - return "Banner{" + - "baseColor='" + baseColor + '\'' + - ", patterns=" + patterns + - '}'; + return "Banner{" + "baseColor='" + baseColor + '\'' + ", patterns=" + patterns + '}'; } @Override @@ -92,8 +88,7 @@ public boolean equals(Object o) { return false; } Banner banner = (Banner) o; - return Objects.equals(baseColor, banner.baseColor) && - Objects.equals(patterns, banner.patterns); + return Objects.equals(baseColor, banner.baseColor) && Objects.equals(patterns, banner.patterns); } @Override @@ -143,10 +138,7 @@ public String getColor() { @Override public String toString() { - return "Pattern{" + - "type='" + type + '\'' + - ", color='" + color + '\'' + - '}'; + return "Pattern{" + "type='" + type + '\'' + ", color='" + color + '\'' + '}'; } @Override @@ -158,8 +150,7 @@ public boolean equals(Object o) { return false; } Pattern pattern = (Pattern) o; - return Objects.equals(type, pattern.type) && - Objects.equals(color, pattern.color); + return Objects.equals(type, pattern.type) && Objects.equals(color, pattern.color); } @Override diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/util/PropertyFilter.java b/hypixel-api-core/src/main/java/net/hypixel/api/util/PropertyFilter.java index 6cb6f1e1..744230b1 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/util/PropertyFilter.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/util/PropertyFilter.java @@ -21,6 +21,13 @@ */ public class PropertyFilter { + // Only these keys are allowed in objects passed through. + protected final Set allowedKeys; + + public PropertyFilter() { + allowedKeys = new HashSet<>(); + } + /** * Shorthand for constructing a new filter that only allows the {@code includedKeys} to pass * through. See {@link #include(String...)} for the key syntax. @@ -31,13 +38,6 @@ public static PropertyFilter including(String... includedKeys) { return filter; } - // Only these keys are allowed in objects passed through. - protected final Set allowedKeys; - - public PropertyFilter() { - allowedKeys = new HashSet<>(); - } - /** * Allows properties with any of the provided {@code keys} to pass through the filter. To * include nested properties, use dots ({@code .}) to separate each parent property from its diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/util/Utilities.java b/hypixel-api-core/src/main/java/net/hypixel/api/util/Utilities.java index a6ec8d2c..1196cc08 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/util/Utilities.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/util/Utilities.java @@ -2,7 +2,12 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import net.hypixel.api.adapters.*; +import net.hypixel.api.adapters.BoostersTypeAdapterFactory; +import net.hypixel.api.adapters.DateTimeTypeAdapter; +import net.hypixel.api.adapters.GameTypeTypeAdapter; +import net.hypixel.api.adapters.PlayerTypeAdapter; +import net.hypixel.api.adapters.ServerTypeTypeAdapter; +import net.hypixel.api.adapters.UUIDTypeAdapter; import net.hypixel.api.data.type.GameType; import net.hypixel.api.data.type.ServerType; import net.hypixel.api.reply.BoostersReply; @@ -16,7 +21,6 @@ public final class Utilities { - private static final Pattern TOKEN_SPLITTER = Pattern.compile("(?(BoostersReply.Booster.class)) .create(); + private static final Pattern TOKEN_SPLITTER = Pattern.compile("(? - hypixel-api diff --git a/hypixel-api-transport-reactor/pom.xml b/hypixel-api-transport-reactor/pom.xml index c327efd5..cee37493 100644 --- a/hypixel-api-transport-reactor/pom.xml +++ b/hypixel-api-transport-reactor/pom.xml @@ -1,6 +1,6 @@ - hypixel-api diff --git a/hypixel-api-transport-reactor/src/main/java/net/hypixel/api/reactor/ReactorHttpClient.java b/hypixel-api-transport-reactor/src/main/java/net/hypixel/api/reactor/ReactorHttpClient.java index 40dbee9f..b0bad0c4 100644 --- a/hypixel-api-transport-reactor/src/main/java/net/hypixel/api/reactor/ReactorHttpClient.java +++ b/hypixel-api-transport-reactor/src/main/java/net/hypixel/api/reactor/ReactorHttpClient.java @@ -15,7 +15,11 @@ import java.time.Duration; import java.util.UUID; -import java.util.concurrent.*; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; @@ -87,6 +91,11 @@ public ReactorHttpClient(UUID apiKey) { this(apiKey, 8, 500); } + private static CompletableFuture toHypixelResponseFuture(Mono> result) { + return result.map(tuple -> new HypixelHttpResponse(tuple.getT2(), tuple.getT1(), tuple.getT3())) + .toFuture(); + } + /** * Canceling the returned future will result in canceling the sending of the request if still possible */ @@ -103,11 +112,6 @@ public CompletableFuture makeAuthenticatedRequest(String ur return toHypixelResponseFuture(makeRequest(url, true)); } - private static CompletableFuture toHypixelResponseFuture(Mono> result) { - return result.map(tuple -> new HypixelHttpResponse(tuple.getT2(), tuple.getT1(), tuple.getT3())) - .toFuture(); - } - @Override public void shutdown() { this.requestCallbackFluxDisposable.dispose(); diff --git a/hypixel-api-transport-unirest/pom.xml b/hypixel-api-transport-unirest/pom.xml index 02c1279c..675a76f6 100644 --- a/hypixel-api-transport-unirest/pom.xml +++ b/hypixel-api-transport-unirest/pom.xml @@ -1,6 +1,6 @@ - hypixel-api