Skip to content

Commit

Permalink
Fixed NPE in FlagListener if provided location is null
Browse files Browse the repository at this point in the history
Fixes #585
  • Loading branch information
Poslovitch committed Mar 1, 2019
1 parent 98e0da6 commit f422a22
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/java/world/bentobox/bentobox/api/flags/FlagListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,34 @@ public void noGo(@NonNull Event e, @NonNull Flag flag, boolean silent) {
* Check if flag is allowed at location. Uses player object because Bukkit events provide player.
* @param e - event
* @param player - player affected by this flag, or null if none
* @param loc - location
* @param loc - location, will return true if null
* @param flag - flag {@link world.bentobox.bentobox.lists.Flags}
* @return true if allowed, false if not
*/
public boolean checkIsland(@NonNull Event e, @Nullable Player player, @NonNull Location loc, @NonNull Flag flag) {
public boolean checkIsland(@NonNull Event e, @Nullable Player player, @Nullable Location loc, @NonNull Flag flag) {
return checkIsland(e, player, loc, flag, false);
}

/**
* Check if flag is allowed at location
* @param e - event
* @param player - player affected by this flag, or null if none
* @param loc - location
* @param loc - location, will return true if null
* @param flag - flag {@link world.bentobox.bentobox.lists.Flags}
* @param silent - if true, no attempt is made to tell the user
* @return true if the check is okay, false if it was disallowed
*/
public boolean checkIsland(@NonNull Event e, @Nullable Player player, @NonNull Location loc, @NonNull Flag flag, boolean silent) {
public boolean checkIsland(@NonNull Event e, @Nullable Player player, @Nullable Location loc, @NonNull Flag flag, boolean silent) {
// Set user
user = User.getInstance(player);
if (loc == null) {
// We cannot report that it's null here (#report(...) would throw a NPE)
return true;
}

// If this is not an Island World or a standard Nether or End, skip
if (!plugin.getIWM().inWorld(loc)) {
report(user, e, loc, flag, Why.UNPROTECTED_WORLD);
report(user, e, loc, flag, Why.UNPROTECTED_WORLD);
return true;
}

Expand Down Expand Up @@ -162,7 +167,6 @@ public boolean checkIsland(@NonNull Event e, @Nullable Player player, @NonNull L
}
report(user, e, loc, flag, Why.NOT_ALLOWED_IN_WORLD);
noGo(e, flag, silent);
// Clear the user for the next time
return false;
}

Expand All @@ -180,7 +184,6 @@ public boolean checkIsland(@NonNull Event e, @Nullable Player player, @NonNull L
}
report(user, e, loc, flag, Why.NOT_ALLOWED_ON_ISLAND);
noGo(e, flag, silent);
// Clear the user for the next time
return false;
}
// The player is in the world, but not on an island, so general world settings apply
Expand All @@ -201,7 +204,6 @@ private void report(@Nullable User user, @NonNull Event e, @NonNull Location loc
plugin.log("Why: " + e.getEventName() + " in world " + loc.getWorld().getName() + " at " + Util.xyz(loc.toVector()));
plugin.log("Why: " + user.getName() + " " + flag.getID() + " - " + why.name());
}

}

/**
Expand Down

0 comments on commit f422a22

Please sign in to comment.