diff --git a/src/main/java/world/bentobox/bentobox/database/objects/Island.java b/src/main/java/world/bentobox/bentobox/database/objects/Island.java index b1b0f4f6c..57dff7e6b 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/Island.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/Island.java @@ -18,6 +18,7 @@ import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.GameMode; import org.bukkit.World.Environment; import org.bukkit.entity.Player; import org.bukkit.util.BoundingBox; @@ -701,6 +702,19 @@ public class Island implements DataObject, MetaDataAble { return new BoundingBox(getMinX(), world.getMinHeight(), getMinZ(), getMaxX(), world.getMaxHeight(), getMaxZ()); } + /** + * Using this method in the filtering for getVisitors and hasVisitors + * @param player + * @return true if player is a visitor + */ + private boolean playerIsVisitor(Player player) { + if (player.getGameMode() == GameMode.SPECTATOR) { + return false; + } + + return onIsland(player.getLocation()) && getRank(User.getInstance(player)) == RanksManager.VISITOR_RANK; + } + /** * Returns a list of players that are physically inside the island's protection range and that are visitors. * @return list of visitors @@ -709,7 +723,7 @@ public class Island implements DataObject, MetaDataAble { @NonNull public List getVisitors() { return Bukkit.getOnlinePlayers().stream() - .filter(player -> onIsland(player.getLocation()) && getRank(User.getInstance(player)) == RanksManager.VISITOR_RANK) + .filter(player -> playerIsVisitor(player)) .collect(Collectors.toList()); } @@ -722,7 +736,7 @@ public class Island implements DataObject, MetaDataAble { * @see #getVisitors() */ public boolean hasVisitors() { - return Bukkit.getOnlinePlayers().stream().anyMatch(player -> onIsland(player.getLocation()) && getRank(User.getInstance(player)) == RanksManager.VISITOR_RANK); + return Bukkit.getOnlinePlayers().stream().anyMatch(player -> playerIsVisitor(player)); } /**