Skip to content

Commit

Permalink
Fixed an NPE when there was no pokeFilter found attached to the channel
Browse files Browse the repository at this point in the history
  • Loading branch information
CBRSightings committed Oct 24, 2017
1 parent 9257757 commit 5b44770
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/notifier/PokeNotificationSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,32 @@ public void run() {
private void postToChannel(PokeChannel channel, PokeSpawn pokeSpawn) {
JsonElement pokeFilter = config.searchPokemonFilter(config.filters.get(channel.filterName), pokeSpawn.id);
//
if (pokeSpawn.getGeofenceIds().size() > 0) {
if (pokeFilter.isJsonObject()) {
JsonObject obj = pokeFilter.getAsJsonObject();
if (pokeFilter == null){
System.out.println(String.format("wtf pokeFilter %s is null for channel with id %s",channel.filterName, channel.channelId));
return;
}
if (pokeFilter.isJsonObject()) {
JsonObject obj = pokeFilter.getAsJsonObject();

JsonElement maxObj = obj.get("max_iv");
JsonElement minObj = obj.get("min_iv");
JsonElement maxObj = obj.get("max_iv");
JsonElement minObj = obj.get("min_iv");

float max = maxObj == null ? 100 : maxObj.getAsFloat();
float min = minObj == null ? 0 : minObj.getAsFloat();
float max = maxObj == null ? 100 : maxObj.getAsFloat();
float min = minObj == null ? 0 : minObj.getAsFloat();

if (pokeSpawn.iv <= max && pokeSpawn.iv >= min) {
notificationLog.log(INFO, String.format("Pokemon between specified ivs (%s,%s), posting to Discord", min, max));
sendPublicAlert(pokeSpawn.buildPublicMessage(), pokeSpawn.getGeofenceIds());
} else {
notificationLog.log(INFO, String.format("Pokemon not specified ivs (%s,%s), posting to Discord", min, max));
if (pokeSpawn.iv <= max && pokeSpawn.iv >= min) {
notificationLog.log(INFO, String.format("Pokemon between specified ivs (%s,%s), posting to Discord", min, max));
sendPublicAlert(pokeSpawn.buildPublicMessage(), pokeSpawn.getGeofenceIds());
} else {
notificationLog.log(INFO, String.format("Pokemon not specified ivs (%s,%s), posting to Discord", min, max));

}
}
} else {
if (pokeFilter.getAsBoolean()) {
notificationLog.log(INFO, "Pokemon enabled in filter, posting to Discord");
sendPublicAlert(pokeSpawn.buildPublicMessage(), pokeSpawn.getGeofenceIds());
} else {
if (pokeFilter.getAsBoolean()) {
notificationLog.log(INFO, "Pokemon enabled in filter, posting to Discord");
sendPublicAlert(pokeSpawn.buildPublicMessage(), pokeSpawn.getGeofenceIds());
} else {
notificationLog.log(INFO, "Pokemon not enabled in filter, not posting");
}
notificationLog.log(INFO, "Pokemon not enabled in filter, not posting");
}
}
}
Expand Down

0 comments on commit 5b44770

Please sign in to comment.