package eu.mhsl.minenet.minigames.command.privileged;

import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
import eu.mhsl.minenet.minigames.message.Icon;
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.entity.Player;

public class OpCommand extends PrivilegedCommand {
    public OpCommand() {
        super("op");

        addSyntax((sender, context) -> {
            Player target = MinecraftServer.getConnectionManager().getOnlinePlayerByUsername(context.getRaw("target"));
            if(target != null) {
                target.setPermissionLevel(4);
                target.refreshCommands();
            } else new ChatMessage(Icon.ERROR).appendStatic("Spieler nicht gefunden").send(sender);
        }, ArgumentType.Entity("target").onlyPlayers(true));
    }
}
