package pw.hamzantal.vagueenchants.commands

import hazae41.minecraft.kutils.bukkit.msg
import org.bukkit.command.CommandSender
import pw.hamzantal.vagueenchants.Msgs
import pw.hamzantal.vagueenchants.subCommands

class Help : Cmd {
	override val firstArg = "help"
	override val usage = "/ve help <command>"
	override val minArgs = 2
	override val description = "&7Show this help menu"

	override val requirePlayer = false
	override val requirePermission = false
	override val permission = ""

	override fun execute(sender: CommandSender, args: Array<String>) {
		sender.msg(Msgs.config.getString("plugin_header").c)
		sender.msg("&c&m------------------")
		subCommands
			.sortedBy { it.firstArg }
			.filter { if (it.requirePermission) sender.hasPermission(it.permission) else true }
			.filter { if (args.size >= 2) it.firstArg.contains(args.component2(), ignoreCase = true) else true }
			.forEach {
				sender.msg("&8Command name: &7${it.firstArg}")
				sender.msg("&8Command usage: &7${it.usage}" + if (it.requirePlayer) " (Player only)" else "")
				sender.msg("&8Command description: &7${it.description}")
				sender.msg("&c&m------------------")
			}
		sender.msg("&7This plugin was created by hhhapz")
	}

}