Handle situtation where sample exists, but does not contain all players
This commit is contained in:
parent
f2177204be
commit
f5238027c7
|
@ -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({});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue