Skip to content

Commit b010532

Browse files
authored
Merge pull request #3 from RaKXeR/master
Add JsonNull checks for habitats and moves
2 parents a75d54c + 4cb4de3 commit b010532

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/main/java/eu/iamgio/pokedex/pokemon/PokemonSpecies.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public static PokemonSpecies fromPokemonName(String pokemonName) throws PokedexE
189189
pokedexNumbers,
190190
Generation.fromJson(json),
191191
evolvesFromSpecies.isJsonNull() ? null : new NamedResource(evolvesFromSpecies.getAsJsonObject()).getName(),
192-
PokemonHabitat.valueOf(new NamedResource(json.get("habitat")).toEnumName()),
192+
json.get("habitat").isJsonNull() ? null : PokemonHabitat.valueOf(new NamedResource(json.get("habitat")).toEnumName()),
193193
NamedResource.getNames(json.getAsJsonArray("egg_groups"))
194194
.stream()
195195
.map(StringUtil::toEnumName)

src/main/java/eu/iamgio/pokedex/pokemon/move/PokemonMove.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class PokemonMove {
3939
/**
4040
* The percent value of how likely this move is to be successful
4141
*/
42-
private int accuracy;
42+
private Integer accuracy;
4343

4444
/**
4545
* The percent value of how likely it is this moves effect will happen. <tt>null</tt> if no effect
@@ -59,7 +59,7 @@ public class PokemonMove {
5959
/**
6060
* The base power of this move
6161
*/
62-
private int power;
62+
private Integer power;
6363

6464
/**
6565
* The elemental type of this move
@@ -141,14 +141,16 @@ public static PokemonMove fromName(String name) throws PokedexException {
141141
);
142142
}
143143
JsonObject meta = json.getAsJsonObject("meta");
144+
JsonElement accuracy = json.get("accuracy");
145+
JsonElement power = json.get("power");
144146
return new PokemonMove(
145147
json.get("id").getAsInt(),
146148
json.get("name").getAsString(),
147-
json.get("accuracy").getAsInt(),
149+
accuracy.isJsonNull() ? null : accuracy.getAsInt(),
148150
effectChance.isJsonNull() ? null : effectChance.getAsInt(),
149151
json.get("pp").getAsInt(),
150152
json.get("priority").getAsByte(),
151-
json.get("power").getAsInt(),
153+
power.isJsonNull() ? null : power.getAsInt(),
152154
PokemonType.valueOf(new NamedResource(json.get("type")).toEnumName()),
153155
MoveAilment.valueOf(new NamedResource(meta.get("ailment")).toEnumName()),
154156
MoveDamageClass.valueOf(new NamedResource(json.get("damage_class")).toEnumName()),

0 commit comments

Comments
 (0)