players plugin /username (lazy) fix

i think sometimes it might break but whatever11!
This commit is contained in:
ChomeNS 2023-03-02 17:11:36 +07:00
parent 97fc506f8a
commit 384d69a99f

View file

@ -42,8 +42,9 @@ class PlayerList {
function inject (bot, dcclient, config) {
bot.players = new PlayerList()
const tabCompleteRequester = {
async getPlayerList () {
const tabCompletePlayerList = {
list: [],
interval: setInterval(async () => {
bot.write('tab_complete', {
text: '/scoreboard players add '
})
@ -52,11 +53,11 @@ function inject (bot, dcclient, config) {
return packet.matches
.filter((match) => !match.tooltip)
.map((match /* what should i name this instead of "match"? */) => match.match)
}
.map(({ match }) => match)
}, 1000 * 3)
}
bot._client.on('player_info', (packet) => {
bot._client.on('player_info', async (packet) => {
for (const player of packet.data) {
switch (packet.action) {
case 0:
@ -115,9 +116,9 @@ function inject (bot, dcclient, config) {
fullPlayer.displayName = player.displayName
}
async function removePlayer (player, packet) {
function removePlayer (player, packet) {
const fullPlayer = bot.players.getPlayer(player)
const players = await tabCompleteRequester.getPlayerList()
const players = tabCompletePlayerList.list
if (fullPlayer && players.some((name) => name === fullPlayer.name)) {
bot.emit('player_vanished', player)
@ -126,6 +127,10 @@ function inject (bot, dcclient, config) {
bot.players.removePlayer(player)
}
}
bot.on('end', () => {
clearInterval(tabCompletePlayerList.interval)
})
}
module.exports = { inject }