Added Island#get- and #hasPlayersOnIsland methods (#861)

* Implements #get and #has - PlayersOnIsland method

Implements methods for #860

* Optimises #hasVisitors and #hasPlayersOnIsland

These methods will now check if there is at least one user that meets the conditions
This commit is contained in:
wellnesscookie 2019-07-27 10:08:46 +02:00 committed by Florian CUNY
parent 8c8d35b966
commit 962833ad60

View File

@ -592,9 +592,33 @@ public class Island implements DataObject {
* @see #getVisitors()
*/
public boolean hasVisitors() {
return !getVisitors().isEmpty();
return Bukkit.getOnlinePlayers().stream().anyMatch(player -> onIsland(player.getLocation()) && getRank(User.getInstance(player)) == RanksManager.VISITOR_RANK);
}
/**
* Returns a list of players that are physically inside the island's protection range
* @return list of players
* @since 1.6.0
*/
@NonNull
public List<Player> getPlayersOnIsland() {
return Bukkit.getOnlinePlayers().stream()
.filter(player -> onIsland(player.getLocation())
.collect(Collectors.toList());
}
/**
* Returns whether this Island has players inside its protection range.
* Note this is equivalent to {@code !island.getPlayersOnIsland().isEmpty()}.
* @return {@code true} if there are players inside this Island's protection range, {@code false} otherwise.
*
* @since 1.6.0
* @see #getPlayersOnIsland()
*/
public boolean hasPlayersOnIsland() {
return Bukkit.getOnlinePlayers().stream().anyMatch(player -> onIsland(player.getLocation()));
}
/**
* Check if the flag is allowed or not
* For flags that are for the island in general and not related to rank.