mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
Handle situtation where sample exists, but does not contain all players
This commit is contained in:
parent
f2177204be
commit
f5238027c7
1 changed files with 8 additions and 4 deletions
|
|
@ -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({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue