package com.zivilon.cinder_loe.command;

import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChatComponentText;

import java.util.UUID;

import static com.zivilon.cinder_loe.character.CharacterEventListener.hiringEnabled;

public class CommandMouthOfSauron extends CommandBase {
    @Override
    public String getCommandName() {
        return "MouthofSauron";
    }

    @Override
    public String getCommandUsage(ICommandSender sender) {
        return "/MouthofSauron <on|off>";
    }

    @Override
    public void processCommand(ICommandSender sender, String[] args) {
        if (!(sender instanceof EntityPlayerMP)) {
            sender.addChatMessage(new ChatComponentText("Only players may use this command."));
            return;
        }
        if (args.length != 1 ||
                (!args[0].equalsIgnoreCase("on") && !args[0].equalsIgnoreCase("off"))) {
            throw new WrongUsageException(getCommandUsage(sender));
        }

        EntityPlayerMP player = (EntityPlayerMP) sender;
        UUID id = player.getUniqueID();
        boolean enable = args[0].equalsIgnoreCase("on");

        if (enable) {
            hiringEnabled.add(id);
            player.addChatMessage(new ChatComponentText("MouthOfSauron auto-hire ENABLED."));
        } else {
            hiringEnabled.remove(id);
            player.addChatMessage(new ChatComponentText("MouthOfSauron auto-hire DISABLED."));
        }
    }
}