Skip to content

Commit 4cb4de3

Browse files
committed
Add JsonNull check for power and accuracy in PokemonMove
1 parent 526208a commit 4cb4de3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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)