Moved some private code into pandalib
This commit is contained in:
parent
b2738a3d33
commit
3b30968c15
@ -21,6 +21,8 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
|
|||||||
|
|
||||||
import fr.pandacube.lib.core.chat.ChatStatic;
|
import fr.pandacube.lib.core.chat.ChatStatic;
|
||||||
import fr.pandacube.lib.core.commands.SuggestionsSupplier;
|
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.Log;
|
||||||
import fr.pandacube.lib.core.util.Reflect;
|
import fr.pandacube.lib.core.util.Reflect;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
@ -215,4 +217,17 @@ public abstract class BrigadierCommand extends ChatStatic {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static final SuggestionsSupplier<CommandSender> 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<CommandSender> 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<CommandSender> TAB_PLAYER_ALL_SERVERS_THEN_OFFLINE = TAB_PLAYER_ALL_SERVERS.orIfEmpty(PlayerFinder.TAB_PLAYER_OFFLINE());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
@ -112,6 +113,34 @@ public abstract class IPlayerManager<OP extends IOnlinePlayer, OF extends IOffPl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<OP> getOnlyVisibleFor(OF viewer) {
|
||||||
|
List<OP> players = getAll();
|
||||||
|
players.removeIf(op -> op.isVanishedFor(viewer));
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OP> getOnlyVisibleFor(OP viewer, boolean sameServerOnly) {
|
||||||
|
if (sameServerOnly && viewer.getServerName() == null)
|
||||||
|
return Collections.emptyList();
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<OP> players = getOnlyVisibleFor((OF)viewer);
|
||||||
|
|
||||||
|
if (sameServerOnly)
|
||||||
|
players.removeIf(op -> !viewer.getServerName().equals(op.getServerName()));
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getNamesOnlyVisibleFor(OP viewer, boolean sameServerOnly) {
|
||||||
|
return getOnlyVisibleFor(viewer, sameServerOnly).stream()
|
||||||
|
.map(IOnlinePlayer::getName)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getNamesOnlyVisibleFor(UUID viewer, boolean sameServerOnly) {
|
||||||
|
return getNamesOnlyVisibleFor(get(viewer), sameServerOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user