RehabCZ

Bukkit get online players except

Dec 22nd, 2025
83
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. public final class PlayerUtils {
  2.  
  3.     private PlayerUtils() {
  4.     }
  5.  
  6.     /**
  7.      * Get all online players except the provided players.
  8.      */
  9.     public static Collection<Player> getPlayersExcept(Player... excluded) {
  10.         Set<UUID> excludedIds = Arrays.stream(excluded)
  11.                 .filter(Objects::nonNull)
  12.                 .map(Player::getUniqueId)
  13.                 .collect(Collectors.toSet());
  14.  
  15.         return Bukkit.getOnlinePlayers().stream()
  16.                 .filter(p -> !excludedIds.contains(p.getUniqueId()))
  17.                 .collect(Collectors.toList());
  18.     }
  19.  
  20.     /**
  21.      * Get all online players except the players with the provided UUIDs.
  22.      */
  23.     public static Collection<Player> getPlayersExcept(UUID... excluded) {
  24.         Set<UUID> excludedIds = Arrays.stream(excluded)
  25.                 .filter(Objects::nonNull)
  26.                 .collect(Collectors.toSet());
  27.  
  28.         return Bukkit.getOnlinePlayers().stream()
  29.                 .filter(p -> !excludedIds.contains(p.getUniqueId()))
  30.                 .collect(Collectors.toList());
  31.     }
  32. }
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment