Skip to content

Commit

Permalink
Actually set online Player count too
Browse files Browse the repository at this point in the history
  • Loading branch information
C0D3-M4513R committed Jul 11, 2023
1 parent fc1fdd4 commit 64d3282
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.ServerInfo;
import com.velocitypowered.api.proxy.server.ServerPing;
import org.slf4j.Logger;

Expand Down Expand Up @@ -44,9 +46,20 @@ public EventTask onServerPing(ProxyPingEvent event) {
event.setPing(event.getPing().asBuilder()
.samplePlayers(
players.stream()
.map(player -> new ServerPing.SamplePlayer(player.getGameProfile().getName(),
player.getUniqueId()))
.toArray(ServerPing.SamplePlayer[]::new))
.map(player -> {
final String serverName = player.getCurrentServer()
.map(ServerConnection::getServerInfo)
.map(ServerInfo::getName)
.map(name -> "["+name+"] ")
.orElse("");
return new ServerPing.SamplePlayer(
serverName + player.getUsername(),
player.getUniqueId()
);
})
.toArray(ServerPing.SamplePlayer[]::new)
).onlinePlayers(players.size())
.maximumPlayers(server.getConfiguration().getShowMaxPlayers())
.build());
}
});
Expand Down

0 comments on commit 64d3282

Please sign in to comment.