2021-03-22 23:06:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
2024-01-01 12:39:45 +01:00
|
|
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
2021-03-22 23:06:40 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-26 20:52:34 +02:00
|
|
|
package com.viaversion.viaversion.commands.defaultsubs;
|
2016-04-17 13:55:18 +02:00
|
|
|
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.api.Via;
|
|
|
|
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
|
|
|
import com.viaversion.viaversion.api.command.ViaSubCommand;
|
2021-04-26 21:35:29 +02:00
|
|
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
2021-04-26 21:16:10 +02:00
|
|
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
2021-04-02 14:15:30 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.TreeMap;
|
2016-04-17 13:55:18 +02:00
|
|
|
|
|
|
|
public class PPSSubCmd extends ViaSubCommand {
|
|
|
|
@Override
|
|
|
|
public String name() {
|
|
|
|
return "pps";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String description() {
|
2023-10-24 04:59:10 +02:00
|
|
|
return "Shows the packets per second of online players.";
|
2016-04-17 13:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String usage() {
|
|
|
|
return "pps";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-09-23 19:49:59 +02:00
|
|
|
public boolean execute(ViaCommandSender sender, String[] args) {
|
2016-04-17 13:55:18 +02:00
|
|
|
Map<Integer, Set<String>> playerVersions = new HashMap<>();
|
|
|
|
int totalPackets = 0;
|
|
|
|
int clients = 0;
|
|
|
|
long max = 0;
|
|
|
|
|
2016-09-25 17:03:03 +02:00
|
|
|
for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) {
|
|
|
|
int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
|
2016-04-17 13:55:18 +02:00
|
|
|
if (!playerVersions.containsKey(playerVersion))
|
2021-04-20 13:19:34 +02:00
|
|
|
playerVersions.put(playerVersion, new HashSet<>());
|
2021-03-24 15:21:18 +01:00
|
|
|
UserConnection uc = Via.getManager().getConnectionManager().getConnectedClient(p.getUUID());
|
2021-04-20 13:19:34 +02:00
|
|
|
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();
|
2016-04-17 13:55:18 +02:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2016-06-19 23:36:15 +02:00
|
|
|
if (clients == 0) {
|
|
|
|
sendMessage(sender, "&cNo clients to display.");
|
|
|
|
}
|
2016-04-17 13:55:18 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|