Filter player lists with counts
closes #161 Co-authored-by: ens-gijs <ens.gijs@gmail.com>
This commit is contained in:
2 files changed
+11
-2
No files matched your search
@@ -123,9 +123,9 @@ public final class MOTDConfig {
|
||||
+ "If false, the online player count will be capped at the maximum player count")
|
||||
private boolean allowExceedingMaximum = false;
|
||||
|
||||
@Comment("The list of server names that affect player counts.\n"
|
||||
@Comment("The list of server names that affect player counts/listing.\n"
|
||||
+ "Only applicable when running the plugin on a proxy (Velocity or Waterfall/Bungeecord).\n"
|
||||
+ "When set to an empty list, the default count determined by the proxy will be used.")
|
||||
+ "When set to an empty list, the default count & list as determined by the proxy will be used.")
|
||||
private final List<String> servers = new ArrayList<>();
|
||||
|
||||
@ConfigSerializable
|
||||
|
||||
@@ -31,7 +31,10 @@ import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.api.util.Favicon;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -64,12 +67,18 @@ public final class PingListener {
|
||||
if (targetServers.isEmpty()) {
|
||||
playersCount = pong.getOnlinePlayers();
|
||||
} else {
|
||||
final Set<ServerPing.SamplePlayer> players = new HashSet<>();
|
||||
for (final String serverName : targetServers) {
|
||||
final @Nullable RegisteredServer server = this.proxy.getServer(serverName).orElse(null);
|
||||
if (server != null) {
|
||||
playersCount += server.getPlayersConnected().size();
|
||||
players.addAll(server.getPlayersConnected().stream()
|
||||
.map(p -> new ServerPing.SamplePlayer(p.getGameProfile().getName(), p.getUniqueId()))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
pong.clearSamplePlayers();
|
||||
pong.samplePlayers(players.toArray(new ServerPing.SamplePlayer[0]));
|
||||
}
|
||||
|
||||
final PingResponse<Favicon> response = this.miniMOTD.createMOTD(config, playersCount, pong.getMaximumPlayers());
|
||||
|
||||
Reference in new issue
Block a user