Compare commits

...

2 commits
main ... main

Author SHA1 Message Date
aaa
af87a06e76 Player vanish checking (solves issue #10) 2024-09-25 12:15:12 -04:00
aaa
b273ef92f8 Add src/modules/tab_complete.js 2024-09-25 11:10:46 -04:00
2 changed files with 34 additions and 6 deletions

View file

@ -18,11 +18,20 @@ function player_list (bot, options, config) {
}
})
bot.on('packet.player_remove', ({ players }) => {
// TODO: Add player removal (with validation)
for (const player of players) {
bot.players = bot.players.filter(entry => entry.uuid !== player)
}
bot.on('packet.player_remove', async ({players}) => { // players has uuids of the players
let player_completion = (await bot.tab_complete('scoreboard players add ')).filter(_ => _.tooltip == undefined) // exclude @a, @r, @s, @e, @p -aaa
bot.players.forEach(async player => {
if(!players.includes(player.uuid)) return
const a = player_completion.filter(_ => _.match == player.profile.name)
if(a.length >= 1) {
player.vanished = true
} else {
bot.players = bot.players.filter(_ => _.uuid != player.uuid)
}
})
})
function addPlayer (entry) {
@ -35,7 +44,8 @@ function player_list (bot, options, config) {
gamemode: undefined,
listed: undefined,
latency: undefined,
displayName: undefined
displayName: undefined,
vanished: false
})
}

View file

@ -0,0 +1,18 @@
module.exports = (bot) => {
// let aaa cook
bot.tab_complete = (str) => {
return new Promise((resolve) => {
bot._client.write('tab_complete', {
text: str, assumeCommand: false, sendBlockInSight: false
})
const tab_completeH = (packet) => {
bot._client.removeListener('tab_complete', tab_completeH)
resolve(packet.matches)
}
bot._client.once('tab_complete', tab_completeH)
})
}
}