package me.km.snuviscript;

import java.util.ArrayList;
import me.hammerle.snuviscript.code.Script;
import me.km.permissions.Command;
import net.minecraft.command.ICommandSource;
import net.minecraft.entity.player.ServerPlayerEntity;

public class CommandGiveUp extends Command {
    private final Scripts scripts;

    public CommandGiveUp(Scripts scripts) {
        this.scripts = scripts;
    }

    @Override
    public String getName() {
        return "giveup";
    }

    @Override
    public Iterable<String> getAliases() {
        ArrayList<String> list = new ArrayList<>();
        list.add("fuckit");
        list.add("fuckitigiveup");
        list.add("ineedhelp");
        list.add("leave");
        list.add("l");
        return list;
    }

    @Override
    public void execute(ICommandSource cs, String[] arg) {
        if(!(cs instanceof ServerPlayerEntity)) {
            sendMessage(cs, "This command is only for players.");
            return;
        }
        ServerPlayerEntity p = (ServerPlayerEntity) cs;
        Script script = scripts.getScript(p);
        if(script == null) {
            scripts.getScriptManager().callEvent("player_no_script", (sc) -> ScriptVars.setPlayerVars(sc, p), null);
            return;
        }
        scripts.getScriptManager().callEvent("player_giveup", script, (sc) -> ScriptVars.setPlayerVars(sc, p), null);
    }
}
