2024-11-19 20:05:19 -05:00
|
|
|
import cmds from '../util/commands.js'
|
|
|
|
import settings from '../settings.js'
|
2024-10-23 23:35:21 -04:00
|
|
|
import Command from '../util/Command.js'
|
2024-11-20 01:34:57 -05:00
|
|
|
import hashcheck from '../util/hashcheck.js'
|
|
|
|
import { getMessage } from '../util/lang.js'
|
2024-10-23 23:35:21 -04:00
|
|
|
export default function load (b) {
|
2024-10-23 23:38:08 -04:00
|
|
|
b.on('chat', (data) => {
|
2024-10-23 23:35:21 -04:00
|
|
|
const fullCommand = data.message
|
|
|
|
for (const prefix of settings.prefixes) {
|
|
|
|
if (fullCommand.startsWith(prefix)) {
|
|
|
|
const command = fullCommand.slice(prefix.length)
|
|
|
|
b.runCommand(data.username, data.nickname, data.uuid, command, data.type, data.subtype, prefix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2024-11-19 20:05:19 -05:00
|
|
|
b.runCommand = function (user, nick, uuid, command, type, subtype, prefix) {
|
2024-11-20 01:34:57 -05:00
|
|
|
if (uuid === '00000000-0000-0000-0000-000000000000') return
|
|
|
|
if (Date.now() - b.lastCmd <= 1000) return
|
|
|
|
b.lastCmd = Date.now()
|
|
|
|
|
|
|
|
const context = new Command(uuid, user, nick, command, 'minecraft', type, subtype, prefix, b)
|
2024-11-07 01:22:04 -05:00
|
|
|
|
|
|
|
b.emit('command', context)
|
2024-11-20 01:34:57 -05:00
|
|
|
if (context.cancel === true) return
|
|
|
|
|
|
|
|
const commandItem = cmds[context.cmdName.toLowerCase()]
|
|
|
|
|
|
|
|
const cmdsplit = command.split(' ')
|
|
|
|
const verify = hashcheck(cmdsplit, uuid)
|
|
|
|
const permsN = getMessage(context.lang, 'command.help.permsNormal')
|
|
|
|
const permsT = getMessage(context.lang, 'command.help.permsTrusted')
|
|
|
|
const permsO = getMessage(context.lang, 'command.help.permsOwner')
|
|
|
|
if (commandItem && commandItem.level !== undefined && commandItem.level > verify) {
|
|
|
|
b.tellraw(uuid, {
|
|
|
|
text: getMessage(context.lang, 'command.disallowed.perms')
|
|
|
|
})
|
|
|
|
b.tellraw(uuid, {
|
|
|
|
text: getMessage(context.lang, 'command.disallowed.perms.yourLevel', [[permsN, permsT, permsO][verify]])
|
|
|
|
})
|
|
|
|
b.tellraw(uuid, {
|
|
|
|
text: getMessage(context.lang, 'command.disallowed.perms.cmdLevel', [[permsN, permsT, permsO][commandItem.level]])
|
|
|
|
})
|
|
|
|
return
|
|
|
|
} else if (verify > 0) {
|
|
|
|
context.rewriteCommand(cmdsplit.slice(0, cmdsplit.length - 1).join(' '))
|
|
|
|
context.verify = verify
|
|
|
|
}
|
2024-11-07 01:22:04 -05:00
|
|
|
|
2024-11-20 01:34:57 -05:00
|
|
|
if (commandItem) {
|
2024-10-23 23:35:21 -04:00
|
|
|
try {
|
2024-11-20 01:34:57 -05:00
|
|
|
commandItem.execute(context)
|
2024-10-23 23:35:21 -04:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e)
|
2024-11-20 01:34:57 -05:00
|
|
|
b.tellraw(uuid, {
|
|
|
|
text: getMessage(context.lang, 'command.error'),
|
2024-11-20 01:39:51 -05:00
|
|
|
color: context.colors.error,
|
2024-11-20 01:34:57 -05:00
|
|
|
hoverEvent: {
|
|
|
|
action: 'show_text',
|
|
|
|
value: {
|
|
|
|
text: e.stack
|
|
|
|
}
|
|
|
|
}
|
2024-10-23 23:35:21 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|