Handle situtation where sample exists, but does not contain all players

This commit is contained in:
Pascal Sthamer 2020-02-18 14:52:04 +01:00
parent f2177204be
commit f5238027c7
No known key found for this signature in database
GPG Key ID: BD32A96DA773ADAF
1 changed files with 8 additions and 4 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({
@ -54,10 +55,13 @@ class MinecraftVanilla extends Core {
name: player.name
});
}
} else {
for (let i = 0; i < Math.min(json.players.online, 10000); i++) {
state.players.push({});
}
}
// players.sample may not contain all players or no players at all, depending on how many players are only.
// 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({});
}
}