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

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({
@ -54,10 +55,13 @@ class MinecraftVanilla extends Core {
name: player.name 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({});
} }
} }