package pw.hamzantal.vagueenchants.commands

import org.bukkit.Bukkit
import org.bukkit.command.CommandSender
import pw.hamzantal.vagueenchants.setTokens
import pw.hamzantal.vagueenchants.uuid

class SetTokens : Cmd {
	override val firstArg = "settokens"
	override val usage = "/ve settokens [player] [amount]"
	override val minArgs = 3
	override val description = "&7Set the tokens a player has"

	override val requirePermission = true
	override val permission = "ve.admin"
	override val requirePlayer = false

	override fun execute(sender: CommandSender, args: Array<String>) {
		val (_, targetName, amt) = args

		val target = Bukkit.getOfflinePlayer(targetName) ?: run {
			sender.err("target_not_found", "player" to targetName)
			return
		}

		val amount = (amt.toLongOrNull() ?: 0)
		if (amount < 0) {
			sender.err("amount_below_zero")
			return
		}
		setTokens(target.uuid, amount)
		sender.success("${target.name} now has $amount tokens.")
		if (target.isOnline)
			target.player.success("settoken_receiver", "token" to amount.toString())
	}
}