mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-10 02:19:30 +01:00
Feat: Filtering spectators from visitors (#1974)
* support 1.18 negative y * feat: visitor gamemode spectator check
This commit is contained in:
parent
6fba4bfbea
commit
4ab579f2cd
@ -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<Player> 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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user