Search in sources :

Example 1 with ViaCommandSender

use of com.viaversion.viaversion.api.command.ViaCommandSender in project ViaVersion by ViaVersion.

the class ViaVersionPlugin method getOnlinePlayers.

@Override
public ViaCommandSender[] getOnlinePlayers() {
    ViaCommandSender[] array = new ViaCommandSender[Bukkit.getOnlinePlayers().size()];
    int i = 0;
    for (Player player : Bukkit.getOnlinePlayers()) {
        array[i++] = new BukkitCommandSender(player);
    }
    return array;
}
Also used : ViaCommandSender(com.viaversion.viaversion.api.command.ViaCommandSender) Player(org.bukkit.entity.Player) BukkitCommandSender(com.viaversion.viaversion.bukkit.commands.BukkitCommandSender)

Example 2 with ViaCommandSender

use of com.viaversion.viaversion.api.command.ViaCommandSender in project ViaVersion by ViaVersion.

the class SpongePlugin method getOnlinePlayers.

@Override
public ViaCommandSender[] getOnlinePlayers() {
    Collection<ServerPlayer> players = game.server().onlinePlayers();
    ViaCommandSender[] array = new ViaCommandSender[players.size()];
    int i = 0;
    for (ServerPlayer player : players) {
        array[i++] = new SpongePlayer(player);
    }
    return array;
}
Also used : ViaCommandSender(com.viaversion.viaversion.api.command.ViaCommandSender) SpongePlayer(com.viaversion.viaversion.sponge.commands.SpongePlayer) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer)

Example 3 with ViaCommandSender

use of com.viaversion.viaversion.api.command.ViaCommandSender in project ViaVersion by ViaVersion.

the class ListSubCmd method execute.

@Override
public boolean execute(ViaCommandSender sender, String[] args) {
    Map<ProtocolVersion, Set<String>> playerVersions = new TreeMap<>((o1, o2) -> ProtocolVersion.getIndex(o2) - ProtocolVersion.getIndex(o1));
    for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) {
        int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
        ProtocolVersion key = ProtocolVersion.getProtocol(playerVersion);
        playerVersions.computeIfAbsent(key, s -> new HashSet<>()).add(p.getName());
    }
    for (Map.Entry<ProtocolVersion, Set<String>> entry : playerVersions.entrySet()) {
        sendMessage(sender, "&8[&6%s&8] (&7%d&8): &b%s", entry.getKey().getName(), entry.getValue().size(), entry.getValue());
    }
    playerVersions.clear();
    return true;
}
Also used : ViaCommandSender(com.viaversion.viaversion.api.command.ViaCommandSender) HashSet(java.util.HashSet) ViaCommandSender(com.viaversion.viaversion.api.command.ViaCommandSender) ViaSubCommand(com.viaversion.viaversion.api.command.ViaSubCommand) TreeMap(java.util.TreeMap) Map(java.util.Map) Set(java.util.Set) Via(com.viaversion.viaversion.api.Via) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) HashSet(java.util.HashSet) Set(java.util.Set) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with ViaCommandSender

use of com.viaversion.viaversion.api.command.ViaCommandSender in project ViaVersion by ViaVersion.

the class BungeePlugin method getOnlinePlayers.

@Override
public ViaCommandSender[] getOnlinePlayers() {
    Collection<ProxiedPlayer> players = getProxy().getPlayers();
    ViaCommandSender[] array = new ViaCommandSender[players.size()];
    int i = 0;
    for (ProxiedPlayer player : players) {
        array[i++] = new BungeeCommandSender(player);
    }
    return array;
}
Also used : ViaCommandSender(com.viaversion.viaversion.api.command.ViaCommandSender) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) BungeeCommandSender(com.viaversion.viaversion.bungee.commands.BungeeCommandSender)

Example 5 with ViaCommandSender

use of com.viaversion.viaversion.api.command.ViaCommandSender in project ViaVersion by ViaVersion.

the class PPSSubCmd method execute.

@Override
public boolean execute(ViaCommandSender sender, String[] args) {
    Map<Integer, Set<String>> playerVersions = new HashMap<>();
    int totalPackets = 0;
    int clients = 0;
    long max = 0;
    for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) {
        int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
        if (!playerVersions.containsKey(playerVersion))
            playerVersions.put(playerVersion, new HashSet<>());
        UserConnection uc = Via.getManager().getConnectionManager().getConnectedClient(p.getUUID());
        if (uc != null && uc.getPacketTracker().getPacketsPerSecond() > -1) {
            playerVersions.get(playerVersion).add(p.getName() + " (" + uc.getPacketTracker().getPacketsPerSecond() + " PPS)");
            totalPackets += uc.getPacketTracker().getPacketsPerSecond();
            if (uc.getPacketTracker().getPacketsPerSecond() > max) {
                max = uc.getPacketTracker().getPacketsPerSecond();
            }
            clients++;
        }
    }
    Map<Integer, Set<String>> sorted = new TreeMap<>(playerVersions);
    sendMessage(sender, "&4Live Packets Per Second");
    if (clients > 1) {
        sendMessage(sender, "&cAverage: &f" + (totalPackets / clients));
        sendMessage(sender, "&cHighest: &f" + max);
    }
    if (clients == 0) {
        sendMessage(sender, "&cNo clients to display.");
    }
    for (Map.Entry<Integer, Set<String>> entry : sorted.entrySet()) sendMessage(sender, "&8[&6%s&8]: &b%s", ProtocolVersion.getProtocol(entry.getKey()).getName(), entry.getValue());
    sorted.clear();
    return true;
}
Also used : ViaCommandSender(com.viaversion.viaversion.api.command.ViaCommandSender) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

ViaCommandSender (com.viaversion.viaversion.api.command.ViaCommandSender)5 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 Via (com.viaversion.viaversion.api.Via)1 ViaSubCommand (com.viaversion.viaversion.api.command.ViaSubCommand)1 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)1 ProtocolVersion (com.viaversion.viaversion.api.protocol.version.ProtocolVersion)1 BukkitCommandSender (com.viaversion.viaversion.bukkit.commands.BukkitCommandSender)1 BungeeCommandSender (com.viaversion.viaversion.bungee.commands.BungeeCommandSender)1 SpongePlayer (com.viaversion.viaversion.sponge.commands.SpongePlayer)1 HashMap (java.util.HashMap)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1 Player (org.bukkit.entity.Player)1 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)1