diff --git a/Bungee/src/main/java/fr/pandacube/lib/bungee/commands/BrigadierCommand.java b/Bungee/src/main/java/fr/pandacube/lib/bungee/commands/BrigadierCommand.java index 955f5d4..b4e41af 100644 --- a/Bungee/src/main/java/fr/pandacube/lib/bungee/commands/BrigadierCommand.java +++ b/Bungee/src/main/java/fr/pandacube/lib/bungee/commands/BrigadierCommand.java @@ -21,6 +21,8 @@ import com.mojang.brigadier.tree.LiteralCommandNode; import fr.pandacube.lib.core.chat.ChatStatic; import fr.pandacube.lib.core.commands.SuggestionsSupplier; +import fr.pandacube.lib.core.players.IPlayerManager; +import fr.pandacube.lib.core.players.PlayerFinder; import fr.pandacube.lib.core.util.Log; import fr.pandacube.lib.core.util.Reflect; import net.md_5.bungee.BungeeCord; @@ -214,5 +216,18 @@ public abstract class BrigadierCommand extends ChatStatic { + + + public static final SuggestionsSupplier TAB_PLAYER_CURRENT_SERVER = (sender, ti, token, a) -> SuggestionsSupplier.collectFilteredStream( + IPlayerManager.getInstance().getNamesOnlyVisibleFor((sender instanceof ProxiedPlayer pl) ? pl.getUniqueId() : null, sender instanceof ProxiedPlayer).stream(), + token); + + public static final SuggestionsSupplier TAB_PLAYER_ALL_SERVERS = (sender, ti, token, a) -> SuggestionsSupplier.collectFilteredStream( + IPlayerManager.getInstance().getNamesOnlyVisibleFor((sender instanceof ProxiedPlayer pl) ? pl.getUniqueId() : null, false).stream(), + token); + + public static final SuggestionsSupplier TAB_PLAYER_ALL_SERVERS_THEN_OFFLINE = TAB_PLAYER_ALL_SERVERS.orIfEmpty(PlayerFinder.TAB_PLAYER_OFFLINE()); + + } \ No newline at end of file diff --git a/Core/src/main/java/fr/pandacube/lib/core/players/IPlayerManager.java b/Core/src/main/java/fr/pandacube/lib/core/players/IPlayerManager.java index 296629d..978b8a9 100644 --- a/Core/src/main/java/fr/pandacube/lib/core/players/IPlayerManager.java +++ b/Core/src/main/java/fr/pandacube/lib/core/players/IPlayerManager.java @@ -8,6 +8,7 @@ import java.util.Map; import java.util.Objects; import java.util.UUID; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -112,6 +113,34 @@ public abstract class IPlayerManager getOnlyVisibleFor(OF viewer) { + List players = getAll(); + players.removeIf(op -> op.isVanishedFor(viewer)); + return players; + } + + public List getOnlyVisibleFor(OP viewer, boolean sameServerOnly) { + if (sameServerOnly && viewer.getServerName() == null) + return Collections.emptyList(); + + @SuppressWarnings("unchecked") + List players = getOnlyVisibleFor((OF)viewer); + + if (sameServerOnly) + players.removeIf(op -> !viewer.getServerName().equals(op.getServerName())); + return players; + } + + public List getNamesOnlyVisibleFor(OP viewer, boolean sameServerOnly) { + return getOnlyVisibleFor(viewer, sameServerOnly).stream() + .map(IOnlinePlayer::getName) + .collect(Collectors.toList()); + } + + public List getNamesOnlyVisibleFor(UUID viewer, boolean sameServerOnly) { + return getNamesOnlyVisibleFor(get(viewer), sameServerOnly); + } +