package com.namelessmc.plugin.spigot;

import com.namelessmc.plugin.common.LanguageHandler.Term;
import com.namelessmc.plugin.common.Permission;
import com.namelessmc.plugin.common.command.CommonCommand;
import com.namelessmc.plugin.common.command.GetNotificationsCommand;
import com.namelessmc.plugin.common.command.RegisterCommand;
import com.namelessmc.plugin.common.command.ReportCommand;
import com.namelessmc.plugin.common.command.UserInfoCommand;
import com.namelessmc.plugin.common.command.VerifyCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;

public class CommonCommandProxy extends Command {

	static final Map<String, Supplier<CommonCommandProxy>> COMMAND_SUPPLIERS = new HashMap<>();

	static {
		COMMAND_SUPPLIERS.put("get-notifications", () -> createCommand(
				new GetNotificationsCommand(NamelessPlugin.getInstance()),
				"get-notifications",
				Term.COMMAND_NOTIFICATIONS_DESCRIPTION,
				Term.COMMAND_NOTIFICATIONS_USAGE,
				Permission.COMMAND_GET_NOTIFICATIONS));

		COMMAND_SUPPLIERS.put("register", () -> createCommand(
				new RegisterCommand(NamelessPlugin.getInstance()),
				"register",
				Term.COMMAND_REGISTER_DESCRIPTION,
				Term.COMMAND_REGISTER_USAGE,
				Permission.COMMAND_REGISTER));

		COMMAND_SUPPLIERS.put("report", () -> createCommand(
				new ReportCommand(NamelessPlugin.getInstance()),
				"report",
				Term.COMMAND_REPORT_DESCRIPTION,
				Term.COMMAND_REPORT_USAGE,
				Permission.COMMAND_REPORT));

		COMMAND_SUPPLIERS.put("user-info", 	() -> createCommand(
				new UserInfoCommand(NamelessPlugin.getInstance()),
				"user-info",
				Term.COMMAND_USERINFO_DESCRIPTION,
				Term.COMMAND_USERINFO_USAGE,
				Permission.COMMAND_USER_INFO));

		COMMAND_SUPPLIERS.put("verify", () -> createCommand(
				new VerifyCommand(NamelessPlugin.getInstance()),
				"verify",
				Term.COMMAND_VALIDATE_DESCRIPTION,
				Term.COMMAND_VALIDATE_USAGE,
				Permission.COMMAND_VERIFY));
	}

	private final CommonCommand commonCommand;

	private CommonCommandProxy(final CommonCommand commonCommand, final String name, final String description, final String usage, final Permission permission, final List<String> aliases) {
		super(name, description, usage, aliases);
		this.setPermission(permission.toString());
		this.commonCommand = commonCommand;
	}

	private static CommonCommandProxy createCommand(final CommonCommand commonCommand, final String configName, final Term description, final Term usage, final Permission permission) {
		return new CommonCommandProxy(commonCommand,
				Config.COMMANDS.getConfig().getString(configName),
				NamelessPlugin.getInstance().getLanguage().getLegacyMessage(description),
				NamelessPlugin.getInstance().getLanguage().getLegacyMessage(usage).replace("{command}", Config.COMMANDS.getConfig().getString(configName)),
				permission,
				Collections.emptyList());
	}

	@Override
	public boolean execute(final CommandSender sender, final String commandLabel, final String[] args) {
		final SpigotCommandSender sender2 = new SpigotCommandSender(sender);

		if (!sender.hasPermission(Objects.requireNonNull(this.getPermission()))) {
			sender2.sendMessage(NamelessPlugin.getInstance().getLanguage().getComponent(Term.COMMAND_NO_PERMISSION));
			return true;
		}

		this.commonCommand.execute(sender2, args, this.getUsage());
		return true;
	}

//	private final String usageMessage;
//	private final Permission permission;
//
//	protected Command(final String name, final Term description, final Term usage, final Permission permission) {
//		super(Config.COMMANDS.getConfig().getString(name),
//				NamelessPlugin.getInstance().getLanguageHandler().getMessage(description),
//				NamelessPlugin.getInstance().getLanguageHandler().getMessage(usage, "command", Config.COMMANDS.getConfig().getString(name)),
//				Collections.emptyList());
//		this.usageMessage = NamelessPlugin.getInstance().getLanguageHandler().getMessage(usage, "command", Config.COMMANDS.getConfig().getString(name));
//		this.permission = permission;
//	}
//
//	@Override
//	public NamelessPlugin getPlugin() {
//		return NamelessPlugin.getInstance();
//	}
//
//	public String getUsageWithoutSlash() {
//		return this.usageMessage;
//	}
//
//	@Override
//	public boolean execute(final CommandSender sender, final String label, final String[] args) {
//		if (!this.permission.hasPermission(sender)) {
//			NamelessPlugin.getInstance().getLanguageHandler().send(Term.COMMAND_NO_PERMISSION, sender);
//			return true;
//		}
//
//		final boolean success = execute(sender, args);
//
//		if (!success) {
//			sender.sendMessage(this.getUsage());
//		}
//
//		return success;
//	}
//
//	public abstract boolean execute(CommandSender sender, String[] args);

}

@@ -3510,1382 +3510,6 @@
 %09%7D%0A%0A
-//%09private final String usageMessage;%0A//%09private final Permission permission;%0A//%0A//%09protected Command(final String name, final Term description, final Term usage, final Permission permission) %7B%0A//%09%09super(Config.COMMANDS.getConfig().getString(name),%0A//%09%09%09%09NamelessPlugin.getInstance().getLanguageHandler().getMessage(description),%0A//%09%09%09%09NamelessPlugin.getInstance().getLanguageHandler().getMessage(usage, %22command%22, Config.COMMANDS.getConfig().getString(name)),%0A//%09%09%09%09Collections.emptyList());%0A//%09%09this.usageMessage = NamelessPlugin.getInstance().getLanguageHandler().getMessage(usage, %22command%22, Config.COMMANDS.getConfig().getString(name));%0A//%09%09this.permission = permission;%0A//%09%7D%0A//%0A//%09@Override%0A//%09public NamelessPlugin getPlugin() %7B%0A//%09%09return NamelessPlugin.getInstance();%0A//%09%7D%0A//%0A//%09public String getUsageWithoutSlash() %7B%0A//%09%09return this.usageMessage;%0A//%09%7D%0A//%0A//%09@Override%0A//%09public boolean execute(final CommandSender sender, final String label, final String%5B%5D args) %7B%0A//%09%09if (!this.permission.hasPermission(sender)) %7B%0A//%09%09%09NamelessPlugin.getInstance().getLanguageHandler().send(Term.COMMAND_NO_PERMISSION, sender);%0A//%09%09%09return true;%0A//%09%09%7D%0A//%0A//%09%09final boolean success = execute(sender, args);%0A//%0A//%09%09if (!success) %7B%0A//%09%09%09sender.sendMessage(this.getUsage());%0A//%09%09%7D%0A//%0A//%09%09return success;%0A//%09%7D%0A//%0A//%09public abstract boolean execute(CommandSender sender, String%5B%5D args);%0A%0A
 %7D%0A

Remove old commented code