diff --git a/hypixel-api-core/pom.xml b/hypixel-api-core/pom.xml index 8291833c..fc0237ad 100644 --- a/hypixel-api-core/pom.xml +++ b/hypixel-api-core/pom.xml @@ -17,6 +17,11 @@ + + net.hypixel + hypixel-data + 0.1.2 + com.google.code.gson gson 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..53392155 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,7 +1,7 @@ package net.hypixel.api.adapters; import com.google.gson.*; -import net.hypixel.api.data.type.GameType; +import net.hypixel.data.type.GameType; import java.lang.reflect.Type; @@ -19,12 +19,12 @@ public JsonElement serialize(GameType src, Type typeOfSrc, JsonSerializationCont @Override public GameType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber()) { - return GameType.fromId(json.getAsInt()); + return GameType.getById(json.getAsInt()).orElse(null); } String raw = json.getAsString(); try { - return GameType.fromId(Integer.parseInt(raw)); + return GameType.getById(Integer.parseInt(raw)).orElse(null); } catch (NumberFormatException ignored) { } @@ -33,6 +33,11 @@ public GameType deserialize(JsonElement json, Type typeOfT, JsonDeserializationC } catch (IllegalArgumentException ignored) { } + try { + return GameType.getByDatabaseName(raw).orElse(null); + } catch (IllegalArgumentException ignored) { + } + return null; } 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..727f5916 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,8 +1,8 @@ package net.hypixel.api.adapters; import com.google.gson.*; -import net.hypixel.api.data.type.GameType; -import net.hypixel.api.data.type.ServerType; +import net.hypixel.data.type.GameType; +import net.hypixel.data.type.ServerType; import java.lang.reflect.Type; @@ -17,10 +17,10 @@ public JsonElement serialize(ServerType src, Type typeOfSrc, JsonSerializationCo public ServerType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String raw = json.getAsString(); try { - return GameType.fromId(Integer.parseInt(raw)); + return GameType.getById(Integer.parseInt(raw)).orElse(null); } catch (NumberFormatException ignored) { } - return ServerType.valueOf(raw); + return ServerType.valueOf(raw).orElse(null); } } diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/data/type/GameType.java b/hypixel-api-core/src/main/java/net/hypixel/api/data/type/GameType.java deleted file mode 100644 index 3f713a6b..00000000 --- a/hypixel-api-core/src/main/java/net/hypixel/api/data/type/GameType.java +++ /dev/null @@ -1,99 +0,0 @@ -package net.hypixel.api.data.type; - -public enum GameType implements ServerType { - QUAKECRAFT("Quakecraft", "Quake", 2), - WALLS("Walls", "Walls", 3), - PAINTBALL("Paintball", "Paintball", 4), - SURVIVAL_GAMES("Blitz Survival Games", "HungerGames", 5), - TNTGAMES("The TNT Games", "TNTGames", 6), - VAMPIREZ("VampireZ", "VampireZ", 7), - WALLS3("Mega Walls", "Walls3", 13), - ARCADE("Arcade", "Arcade", 14), - ARENA("Arena Brawl", "Arena", 17), - MCGO("Cops and Crims", "MCGO", 21), - UHC("UHC Champions", "UHC", 20), - BATTLEGROUND("Warlords", "Battleground", 23), - SUPER_SMASH("Smash Heroes", "SuperSmash", 24), - GINGERBREAD("Turbo Kart Racers", "GingerBread", 25), - HOUSING("Housing", "Housing", 26), - SKYWARS("SkyWars", "SkyWars", 51), - TRUE_COMBAT("Crazy Walls", "TrueCombat", 52), - SPEED_UHC("Speed UHC", "SpeedUHC", 54), - SKYCLASH("SkyClash", "SkyClash", 55), - LEGACY("Classic Games", "Legacy", 56), - PROTOTYPE("Prototype", "Prototype", 57), - BEDWARS("Bed Wars", "Bedwars", 58), - MURDER_MYSTERY("Murder Mystery", "MurderMystery", 59), - BUILD_BATTLE("Build Battle", "BuildBattle", 60), - DUELS("Duels", "Duels", 61), - SKYBLOCK("SkyBlock", "SkyBlock", 63), - PIT("Pit", "Pit", 64), - REPLAY("Replay", "Replay", 65), - SMP("SMP", "SMP", 67), - WOOL_GAMES("Wool Wars", "WoolGames", 68), - ; - - private static final GameType[] VALUES = values(); - - private final String name, dbName; - private final int id; - - GameType(String name, String dbName, int id) { - this.name = name; - this.dbName = dbName; - this.id = id; - } - - /** - * @param id The internal id - * @return The GameType associated with that id, or null if there isn't one. - */ - public static GameType fromId(int id) { - for (GameType gameType : VALUES) { - if (gameType.id == id) { - return gameType; - } - } - return null; - } - - /** - * @param dbName The key used in the database - * @return The GameType associated with that key, or null if there isn't one. - */ - public static GameType fromDatabase(String dbName) { - for (GameType gameType : VALUES) { - if (gameType.dbName.equals(dbName)) { - return gameType; - } - } - return null; - } - - /** - * Exposing this method allows people to use the array without cloning. - * Slightly faster but not as safe since the array could be modified. - */ - public static GameType[] getValues() { - return VALUES; - } - - /** - * @return The official name of the GameType - */ - @Override - public String getName() { - return name; - } - - /** - * @return The internal ID that is occasionally used in various database schemas - */ - public int getId() { - return id; - } - - public String getDbName() { - return dbName; - } -} diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/data/type/LobbyType.java b/hypixel-api-core/src/main/java/net/hypixel/api/data/type/LobbyType.java deleted file mode 100644 index 1e69336d..00000000 --- a/hypixel-api-core/src/main/java/net/hypixel/api/data/type/LobbyType.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.hypixel.api.data.type; - -/** - * A LobbyType is used for lobbies which do not have a gametype linked. - */ -public enum LobbyType implements ServerType { - MAIN("Main Lobby"), - TOURNAMENT("Tournament Hall"), - ; - - private static final LobbyType[] VALUES = values(); - - private final String name; - - LobbyType(String name) { - this.name = name; - } - - /** - * Exposing this method allows people to use the array without cloning. - * Slightly faster but not as safe since the array could be modified. - */ - public static LobbyType[] getValues() { - return VALUES; - } - - @Override - public String getName() { - return name; - } -} 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 deleted file mode 100644 index aa73aa21..00000000 --- a/hypixel-api-core/src/main/java/net/hypixel/api/data/type/ServerType.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.hypixel.api.data.type; - -public interface ServerType { - - String name(); - - String getName(); - - static ServerType valueOf(String value) { - try { - return GameType.valueOf(value); - } catch (IllegalArgumentException e) { - // ignored - } - - try { - return LobbyType.valueOf(value); - } catch (IllegalArgumentException e) { - // ignored - } - - return null; - } - -} diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/BoostersReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/BoostersReply.java index 1ba05d32..44c85f8c 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/reply/BoostersReply.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/BoostersReply.java @@ -1,6 +1,6 @@ package net.hypixel.api.reply; -import net.hypixel.api.data.type.GameType; +import net.hypixel.data.type.GameType; import java.time.ZonedDateTime; import java.util.List; 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..b71664e3 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 @@ -1,10 +1,10 @@ package net.hypixel.api.reply; import com.google.gson.annotations.SerializedName; -import net.hypixel.api.data.type.GameType; import net.hypixel.api.data.type.GuildAchievement; import net.hypixel.api.reply.PlayerReply.Player; import net.hypixel.api.util.Banner; +import net.hypixel.data.type.GameType; import java.time.LocalDate; import java.time.ZonedDateTime; diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/LeaderboardsReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/LeaderboardsReply.java index 51896dc4..e5348876 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/reply/LeaderboardsReply.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/LeaderboardsReply.java @@ -1,6 +1,6 @@ package net.hypixel.api.reply; -import net.hypixel.api.data.type.GameType; +import net.hypixel.data.type.GameType; import java.util.List; import java.util.Map; diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/PlayerReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/PlayerReply.java index 914d5516..0826da45 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/reply/PlayerReply.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/PlayerReply.java @@ -5,13 +5,13 @@ import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import net.hypixel.api.HypixelAPI; -import net.hypixel.api.data.type.GameType; import net.hypixel.api.pets.IPetRepository; import net.hypixel.api.pets.PetStats; import net.hypixel.api.pets.impl.compatibility.BackwardsCompatibilityPetRepositoryImpl; import net.hypixel.api.util.ILeveling; import net.hypixel.api.util.UnstableHypixelObject; import net.hypixel.api.util.Utilities; +import net.hypixel.data.type.GameType; import java.lang.reflect.Type; import java.time.ZonedDateTime; diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/RecentGamesReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/RecentGamesReply.java index e551e76c..a8500fd4 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/reply/RecentGamesReply.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/RecentGamesReply.java @@ -1,6 +1,6 @@ package net.hypixel.api.reply; -import net.hypixel.api.data.type.GameType; +import net.hypixel.data.type.GameType; import java.time.ZonedDateTime; import java.util.List; diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/reply/StatusReply.java b/hypixel-api-core/src/main/java/net/hypixel/api/reply/StatusReply.java index 93578e51..156c41a4 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/reply/StatusReply.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/reply/StatusReply.java @@ -1,7 +1,7 @@ package net.hypixel.api.reply; import com.google.gson.annotations.SerializedName; -import net.hypixel.api.data.type.ServerType; +import net.hypixel.data.type.ServerType; public class StatusReply extends RateLimitedReply { 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..5dcb8ba2 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 @@ -3,10 +3,10 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import net.hypixel.api.adapters.*; -import net.hypixel.api.data.type.GameType; -import net.hypixel.api.data.type.ServerType; import net.hypixel.api.reply.BoostersReply; import net.hypixel.api.reply.PlayerReply.Player; +import net.hypixel.data.type.GameType; +import net.hypixel.data.type.ServerType; import java.time.Instant; import java.time.ZoneId; diff --git a/hypixel-api-example/src/main/java/net/hypixel/api/example/GetGuildExample.java b/hypixel-api-example/src/main/java/net/hypixel/api/example/GetGuildExample.java index f6a6c168..3fd07f80 100644 --- a/hypixel-api-example/src/main/java/net/hypixel/api/example/GetGuildExample.java +++ b/hypixel-api-example/src/main/java/net/hypixel/api/example/GetGuildExample.java @@ -1,18 +1,19 @@ package net.hypixel.api.example; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.concurrent.ExecutionException; import net.hypixel.api.HypixelAPI; -import net.hypixel.api.data.type.GameType; import net.hypixel.api.data.type.GuildAchievement; import net.hypixel.api.reply.GuildReply; import net.hypixel.api.reply.GuildReply.Guild; import net.hypixel.api.reply.GuildReply.Guild.Member; import net.hypixel.api.reply.GuildReply.Guild.Rank; import net.hypixel.api.util.IGuildLeveling; +import net.hypixel.data.type.GameType; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.concurrent.ExecutionException; /** * A sample app for demonstrating how guilds can be fetched & used from the Hypixel API.