26 lines
651 B
JavaScript
26 lines
651 B
JavaScript
const nbt = require('prismarine-nbt')
|
|
const snbt = require('../snbt.js')
|
|
const toNbtUuid = require('../uuid-to-nbt-uuid.js')
|
|
|
|
function escapeString (input) {
|
|
let string = '"'
|
|
|
|
for (let i = 0; i < input.length; i++) {
|
|
const c = input[i]
|
|
if (c === '\\' || c === '"') string += '\\' + c
|
|
else string += c
|
|
}
|
|
|
|
string += '"'
|
|
return string
|
|
}
|
|
|
|
function createNameSelector (username) {
|
|
return `@a[limit=1,name=${escapeString(username)}]`
|
|
}
|
|
|
|
function createUuidSelector (uuid) {
|
|
return `@a[limit=1,nbt=${snbt.stringify(nbt.comp({ UUID: toNbtUuid(uuid) }))}]`
|
|
}
|
|
|
|
module.exports = { escapeString, createNameSelector, createUuidSelector }
|