const nbt = require('prismarine-nbt')
const snbt = require('mojangson')
const toNBTUUID = require('../util/uuid-to-nbt-uuid.js')

function bot (bot) {
  function execute (command) {
    bot.core.run(`minecraft:execute ${bot.server.isKaboom ? 'unless entity @s[name= run ] ' : ''}${command}`)
  }

  function kick (target) {
    if (/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/.test(target)) {
      target = `@p[nbt=${snbt.stringify(nbt.comp({ UUID: toNBTUUID(target) }))}]`
    }

    if (bot.server.isKaboom) bot.core.run(`minecraft:item replace entity ${target} container.9 with stone{i:"\xa74${'\u0d9e'.repeat(30000)}\xa7r"}`)
    else bot.core.run('minecraft:kick ' + target)
  }

  bot.execute = execute
  bot.kick = kick
}

module.exports = { bot }