2024-08-12 05:13:32 -04:00
|
|
|
const parse = require('../util/chatparse_plain')
|
|
|
|
const parseNBT = require('../util/parseNBT')
|
2024-07-28 02:37:31 -04:00
|
|
|
module.exports = {
|
2024-08-12 05:13:32 -04:00
|
|
|
load: (b) => {
|
2024-07-28 02:37:31 -04:00
|
|
|
b.players = {}
|
|
|
|
b._client.on('player_info', (data) => {
|
|
|
|
const buffer2 = {}
|
2024-08-22 07:34:39 -04:00
|
|
|
for (const player of data.data) {
|
2024-07-28 02:37:31 -04:00
|
|
|
let uuid
|
2024-08-22 07:34:39 -04:00
|
|
|
if (player.uuid) {
|
|
|
|
uuid = player.uuid
|
|
|
|
} else if (player.UUID) {
|
|
|
|
uuid = player.UUID
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-08-12 05:13:32 -04:00
|
|
|
let displayName
|
2024-08-22 07:34:39 -04:00
|
|
|
if (player.displayName !== undefined) {
|
|
|
|
displayName = player.displayName
|
2024-08-12 05:13:32 -04:00
|
|
|
} else {
|
|
|
|
displayName = '{"text":"[[[[ No display name ]]]]"}'
|
|
|
|
}
|
2024-08-22 07:34:39 -04:00
|
|
|
if (player.player && player.player.name !== undefined) {
|
|
|
|
buffer2[uuid] = { realName: player.player.name, displayName: parse(parseNBT(displayName)) }
|
|
|
|
} else if (player.name !== undefined) {
|
|
|
|
buffer2[uuid] = { realName: player.name, displayName: parse(parseNBT(displayName)) }
|
|
|
|
} else if (player.displayName !== undefined) {
|
|
|
|
buffer2[uuid] = { displayName: parse(parseNBT(displayName)) }
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
}
|
|
|
|
for (const uuid in buffer2) {
|
|
|
|
if (!b.players[uuid]) b.players[uuid] = { displayName: '', realName: '' }
|
|
|
|
if (buffer2[uuid].displayName) b.players[uuid].displayName = buffer2[uuid].displayName
|
|
|
|
if (buffer2[uuid].realName) b.players[uuid].realName = buffer2[uuid].realName
|
|
|
|
}
|
|
|
|
})
|
|
|
|
b.findUUID = (name) => {
|
|
|
|
for (const i in b.players) {
|
|
|
|
if (b.players[i].realName === name) {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '00000000-0000-0000-0000-000000000000'
|
|
|
|
}
|
|
|
|
b.findRealName = (name) => {
|
|
|
|
for (const i in b.players) {
|
|
|
|
if (b.players[i].displayName === name) {
|
|
|
|
return b.players[i].realName
|
|
|
|
}
|
|
|
|
}
|
2024-08-12 05:13:32 -04:00
|
|
|
return '[[[[ no name ]]]]'
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-09-19 22:52:42 -04:00
|
|
|
b.findRealNameFromUUID = (uuid) => {
|
|
|
|
if (b.players[uuid]) {
|
|
|
|
return b.players[uuid].realName
|
2024-08-22 07:34:39 -04:00
|
|
|
} else {
|
|
|
|
return '[[[[ no name ]]]]'
|
|
|
|
}
|
|
|
|
}
|
2024-09-19 22:52:42 -04:00
|
|
|
b.findDisplayName = (uuid) => {
|
|
|
|
if (b.players[uuid]) {
|
|
|
|
const displayName = b.players[uuid].displayName.split(' ')
|
2024-08-22 07:34:39 -04:00
|
|
|
return displayName[displayName.length - 1]
|
|
|
|
} else {
|
|
|
|
return '[[[[ No display name ]]]]'
|
|
|
|
}
|
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
}
|
|
|
|
}
|