mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -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) {
|
function inject (bot, dcclient, config) {
|
||||||
bot.players = new PlayerList()
|
bot.players = new PlayerList()
|
||||||
|
|
||||||
const tabCompleteRequester = {
|
const tabCompletePlayerList = {
|
||||||
async getPlayerList () {
|
list: [],
|
||||||
|
interval: setInterval(async () => {
|
||||||
bot.write('tab_complete', {
|
bot.write('tab_complete', {
|
||||||
text: '/scoreboard players add '
|
text: '/scoreboard players add '
|
||||||
})
|
})
|
||||||
|
@ -52,11 +53,11 @@ function inject (bot, dcclient, config) {
|
||||||
|
|
||||||
return packet.matches
|
return packet.matches
|
||||||
.filter((match) => !match.tooltip)
|
.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) {
|
for (const player of packet.data) {
|
||||||
switch (packet.action) {
|
switch (packet.action) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -115,9 +116,9 @@ function inject (bot, dcclient, config) {
|
||||||
fullPlayer.displayName = player.displayName
|
fullPlayer.displayName = player.displayName
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removePlayer (player, packet) {
|
function removePlayer (player, packet) {
|
||||||
const fullPlayer = bot.players.getPlayer(player)
|
const fullPlayer = bot.players.getPlayer(player)
|
||||||
const players = await tabCompleteRequester.getPlayerList()
|
const players = tabCompletePlayerList.list
|
||||||
|
|
||||||
if (fullPlayer && players.some((name) => name === fullPlayer.name)) {
|
if (fullPlayer && players.some((name) => name === fullPlayer.name)) {
|
||||||
bot.emit('player_vanished', player)
|
bot.emit('player_vanished', player)
|
||||||
|
@ -126,6 +127,10 @@ function inject (bot, dcclient, config) {
|
||||||
bot.players.removePlayer(player)
|
bot.players.removePlayer(player)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bot.on('end', () => {
|
||||||
|
clearInterval(tabCompletePlayerList.interval)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { inject }
|
module.exports = { inject }
|
||||||
|
|
Loading…
Reference in a new issue