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

View file

@ -47,6 +47,7 @@ class MinecraftVanilla extends Core {
state.raw = json; state.raw = json;
state.maxplayers = json.players.max; state.maxplayers = json.players.max;
if(json.players.sample) { if(json.players.sample) {
for(const player of json.players.sample) { for(const player of json.players.sample) {
state.players.push({ 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({}); state.players.push({});
} }
} }