package land.chipmunk.chipmunkmod.modules;

import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.server.permissions.Permissions;

public class KaboomCheck {
    public static final KaboomCheck INSTANCE = new KaboomCheck();
    private static final String CHECKED_COMMAND_OP = "extras:prefix"; // Added circa 2018
    private static final String CHECKED_COMMAND = "minecraft:op"; // It'd be a bit weird for non-Kaboom servers to allow /op without OP...
    private final Minecraft client = Minecraft.getInstance();
    public boolean isKaboom = false;

    public void onJoin () {
        this.isKaboom = false;
    }

    public void onCommandTree (final CommandDispatcher<SharedSuggestionProvider> dispatcher) {
        assert client.player != null; // We can only receive this packet while in a server
        final String checkedCommand = client.player.permissions().hasPermission(Permissions.COMMANDS_OWNER)
                ? CHECKED_COMMAND_OP : CHECKED_COMMAND;

        this.isKaboom = dispatcher.getRoot().getChild(checkedCommand) != null;
    }
}
