mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-13 18:34:54 -05:00
players plugin /username (lazy) fix
i think sometimes it might break but whatever11!
This commit is contained in:
parent
97fc506f8a
commit
384d69a99f
1 changed files with 12 additions and 7 deletions
|
@ -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 }
|
||||
|
|
Loading…
Reference in a new issue