mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-10-05 01:57:31 +02:00
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:
parent
8c8d35b966
commit
962833ad60
@ -592,7 +592,31 @@ public class Island implements DataObject {
|
|||||||
* @see #getVisitors()
|
* @see #getVisitors()
|
||||||
*/
|
*/
|
||||||
public boolean hasVisitors() {
|
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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user