package ru.redguy.qseller;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

import java.util.List;

public class QSellerCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        switch (args.length) {
            case 0: {
                if(sender instanceof Player) {
                    if(sender.hasPermission("qseller.open")) {
                        new QSellerMenu().open((Player) sender);
                    } else {
                        sender.sendMessage(QSeller.getInstance().getParsedString("messages.notAnyWhere"));
                    }
                } else {
                    sender.sendMessage(QSeller.getInstance().getParsedString("messages.mustBePlayer"));
                }
                break;
            }
            case 1: {
                if(args[0].equals("reload")) {
                    if(sender.hasPermission("qseller.reload")) {
                        QSeller.getInstance().reloadConfig();
                    } else {
                        sender.sendMessage(QSeller.getInstance().getParsedString("messages.noPerm"));
                    }
                } else if(Bukkit.getPlayer(args[0])!=null) {
                    if(sender.hasPermission("qseller.open.others")) {
                        new QSellerMenu().open(Bukkit.getPlayer(args[0]));
                    } else {
                        sender.sendMessage(QSeller.getInstance().getParsedString("messages.noPerm"));
                    }
                }
                break;
            }
        }

        return true;
    }

    public static class TabComplete implements TabCompleter {
        @Override
        public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
            return null;
        }
    }
}
