package dev.okenote.advancement;

import dev.okenote.JediCraft;
import dev.okenote.database.User;
import dev.okenote.database.UserData;
import dev.okenote.entities.player.JediPlayer;
import dev.okenote.managers.ChatManager;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.experimental.FieldDefaults;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandContext;
import net.minestom.server.command.builder.arguments.Argument;
import net.minestom.server.entity.Player;
import net.minestom.server.utils.entity.EntityFinder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Getter
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public abstract class JediCommand extends Command {

    JediCraft jediCraft;

    public JediCommand(@NotNull JediCraft jediCraft, @NotNull String name, @Nullable String... aliases) {
        super(name, aliases);
        this.jediCraft = jediCraft;
    }

    public JediCommand(@NotNull JediCraft jediCraft, @NotNull String name) {
        super(name);
        this.jediCraft = jediCraft;
    }

    public void defaultExecutor(@NotNull String permission, @NotNull JediExecutor executor) {
        defaultExecutor(permission, true, executor);
    }

    public void defaultExecutor(@NotNull JediExecutor executor) {
        defaultExecutor("", false, executor);
    }

    public void defaultExecutor(@NotNull String permission, boolean isPermission, @NotNull JediExecutor executor) {
        setDefaultExecutor((sender, context) -> {
            if (sender instanceof Player player) {
                JediPlayer jediPlayer = new JediPlayer(player);
                User user = jediPlayer.getUser();
                UserData userData = jediPlayer.getUserData();
                ChatManager chatManager = jediCraft.getManagerLayer().getChatManager();

                if (isPermission) jediPlayer.hasPermission(permission);

                executor.execute(player, jediPlayer, user, userData, chatManager, context);
            } else System.out.println("Команды может отправлять только игрок!");
        });
    }

    public void syntax(@NotNull String permission, @NotNull JediExecutor executor, @NotNull Argument<?>... arguments) {
        syntax(permission, true, executor);
    }

    public void syntax(@NotNull JediExecutor executor, @NotNull Argument<?>... arguments) {
        syntax("", false, executor);
    }

    public void syntax(@NotNull String permission, boolean isPermission, @NotNull JediExecutor executor, @NotNull Argument<?>... arguments) {
        addSyntax((sender, context) -> {
            if (sender instanceof Player player) {
                JediPlayer jediPlayer = new JediPlayer(player);
                User user = jediPlayer.getUser();
                UserData userData = jediPlayer.getUserData();
                ChatManager chatManager = jediCraft.getManagerLayer().getChatManager();

                if (isPermission) jediPlayer.hasPermission(permission);

                executor.execute(player, jediPlayer, user, userData, chatManager, context);
            } else System.out.println("Команды может отправлять только игрок!");
        }, arguments);
    }

    public void syntaxTarget(@NotNull String permission, @NotNull JediExecutorWithTarget executor, @NotNull Argument<?>... arguments) {
        syntaxTarget(permission, true, executor, arguments);
    }

    public void syntaxTarget(@NotNull JediExecutorWithTarget executor, @NotNull Argument<?>... arguments) {
        syntaxTarget("", false, executor, arguments);
    }

    public void syntaxTarget(@NotNull String permission, boolean isPermission, @NotNull JediExecutorWithTarget executor, @NotNull Argument<?>... arguments) {
        syntax(permission, isPermission, (player, jediPlayer, user, userData, chat, context) -> {
            EntityFinder targetPlayer = context.get("target");

            targetPlayer.find(player).forEach(entity -> {
                if (entity instanceof Player target) {
                    if (!target.isOnline()) return;

                    JediPlayer jediTarget = new JediPlayer(target);
                    User userTarget = jediTarget.getUser();
                    UserData userDataTarget = jediTarget.getUserData();

                    executor.execute(player, jediPlayer, user, userData, target, jediTarget, userTarget, userDataTarget, chat, context);
                }
            });
        }, arguments);
    }

    @FunctionalInterface
    public interface JediExecutor {
        void execute(Player player,
                     JediPlayer jediPlayer,
                     User user,
                     UserData userData,

                     ChatManager chat,
                     CommandContext context);
    }

    @FunctionalInterface
    public interface JediExecutorWithTarget {
        void execute(Player player,
                     JediPlayer jediPlayer,
                     User user,
                     UserData userData,

                     Player target,
                     JediPlayer jediTarget,
                     User userTarget,
                     UserData userDataTarget,

                     ChatManager chat,
                     CommandContext context);
    }
}

Класс полностью работоспособный, сделай его проще и читабельнее