const name = 'mail' const description = 'Shows mail.' const usages = ['send ', 'list', 'clear'] const aliases = ['mail'] const enabled = true const permLevel = 0 const nbt = require('prismarine-nbt') const SNBT = require('../util/snbt.js') const toNBTUUID = require('../util/uuid-to-nbt-uuid.js') function execute (bot, cmd, player, args, handler) { const subCmd = args.shift() let u, message, messages, msg switch (subCmd) { case 'send': u = args.shift() message = args.join(' ') bot.sendMail(player.name, bot.players[u].name ?? u, message) bot.core.run(`minecraft:tellraw @a[nbt=${SNBT.stringify(nbt.comp({ UUID: toNBTUUID(player.UUID) }))}] ${JSON.stringify([ { text: 'Sent ', color: bot.colors.primary }, { text: message, color: bot.colors.secondary }, ' to ', { text: u, color: bot.colors.secondary }, '.' ])}`) break case 'list': messages = bot.mail[player.name] if (!messages || messages.length < 1) return bot.core.run(`minecraft:tellraw @a[nbt=${SNBT.stringify(nbt.comp({ UUID: toNBTUUID(player.UUID) }))}] ${JSON.stringify({ text: 'You have no mail', color: bot.colors.primary })}`) msg = [{ text: 'Mail:\n', color: bot.colors.primary }] messages.forEach((message) => { msg.push(`${message.sender} (from ${message.host}): `) msg.push({ text: `${message.message}\n`, color: bot.colors.secondary }) }) msg[msg.length - 1].text = msg[msg.length - 1].text.slice(0, -1) bot.core.run(`minecraft:tellraw @a[nbt=${SNBT.stringify(nbt.comp({ UUID: toNBTUUID(player.UUID) }))}] ${JSON.stringify(msg)}`) break case 'clear': bot.mail[player.name] = [] bot.core.run(`minecraft:tellraw @a[nbt=${SNBT.stringify(nbt.comp({ UUID: toNBTUUID(player.UUID) }))}] ${JSON.stringify([ { text: 'Your mail has been cleared.', color: bot.colors.primary } ])}`) } } module.exports = { name, description, usages, aliases, enabled, execute, permLevel }