Skip to content

Commit 47b94c8

Browse files
committed
Improve GameTypeTypeAdapter so we don't exception for unknown games
1 parent 6552b2a commit 47b94c8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

hypixel-api-core/src/main/java/net/hypixel/api/adapters/GameTypeTypeAdapter.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ public JsonElement serialize(GameType src, Type typeOfSrc, JsonSerializationCont
1818

1919
@Override
2020
public GameType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
21+
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber()) {
22+
return GameType.fromId(json.getAsInt());
23+
}
24+
2125
String raw = json.getAsString();
2226
try {
2327
return GameType.fromId(Integer.parseInt(raw));
2428
} catch (NumberFormatException ignored) {
2529
}
26-
return GameType.valueOf(raw);
30+
31+
try {
32+
return GameType.valueOf(raw);
33+
} catch (IllegalArgumentException ignored) {
34+
}
35+
36+
return null;
2737
}
2838

2939
}

0 commit comments

Comments
 (0)