From 384d69a99f801d0fb8ac76cc168cb34ea539fef0 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Thu, 2 Mar 2023 17:11:36 +0700 Subject: [PATCH] players plugin /username (lazy) fix i think sometimes it might break but whatever11! --- plugins/players.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/players.js b/plugins/players.js index eea16d4..0a0e156 100644 --- a/plugins/players.js +++ b/plugins/players.js @@ -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 }