diff --git a/src/main/java/world/bentobox/bentobox/api/flags/FlagListener.java b/src/main/java/world/bentobox/bentobox/api/flags/FlagListener.java index 5de42aebc..dd552bb4c 100644 --- a/src/main/java/world/bentobox/bentobox/api/flags/FlagListener.java +++ b/src/main/java/world/bentobox/bentobox/api/flags/FlagListener.java @@ -103,11 +103,11 @@ 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); } @@ -115,17 +115,22 @@ public boolean checkIsland(@NonNull Event e, @Nullable Player player, @NonNull L * 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; } @@ -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; } @@ -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 @@ -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()); } - } /**