Merge pull request #163 from P4sca1/master

Fix wrong player count in minecraftvanilla protocol
This commit is contained in:
Michael Morrison 2020-07-04 22:32:02 -05:00 committed by GitHub
commit 1a3e778c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -47,6 +47,7 @@ class MinecraftVanilla extends Core {
state.raw = json;
state.maxplayers = json.players.max;
if(json.players.sample) {
for(const player of json.players.sample) {
state.players.push({
@ -55,7 +56,11 @@ class MinecraftVanilla extends Core {
});
}
}
for (let i = 0; i < Math.min(json.players.online, 10000); i++) {
// players.sample may not contain all players or no players at all, depending on how many players are online.
// Insert a dummy player object for every online player that is not listed in players.sample.
// Limit player amount to 10.000 players for performance reasons.
for (let i = state.players.length; i < Math.min(json.players.online, 10000); i++) {
state.players.push({});
}
}