package pw.hamzantal.mdranks.commands

import org.bukkit.Bukkit
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import pw.hamzantal.mdranks.Config
import pw.hamzantal.mdranks.api.Vault
import pw.hamzantal.mdranks.err
import pw.hamzantal.mdranks.general

fun checkBalance(sender: CommandSender, args: Array<String>) {
	if (sender is Player) {
		if (args.isEmpty()) {
			sender.general("balance_format", "balance" to Config.formatC(Vault.balance(sender)))
			return
		}
	} else {
		if (args.isEmpty()) sender.err("You must be a player to use this. /bal [player].")
		return
	}
	val target = Bukkit.getPlayer(args.component1()) ?: sender.run {
		this.err("player_not_found")
		return
	}
	sender.general(
		"other_balance",
		"player" to target.name.toUpperCase(),
		"balance" to Config.formatC(Vault.balance(target))
	)
}
