package com.ptsmods.morecommands.commands.client;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.ptsmods.morecommands.MoreCommands;
import com.ptsmods.morecommands.MoreCommandsClient;
import com.ptsmods.morecommands.api.IMoreGameRules;
import com.ptsmods.morecommands.api.clientoptions.ClientOption;
import com.ptsmods.morecommands.miscellaneous.ClientCommand;
import java.util.Locale;
import net.minecraft.Util;
import net.minecraft.client.multiplayer.ClientSuggestionProvider;

public class DocsCommand extends ClientCommand {
    @Override
    public void cRegister(CommandDispatcher<ClientSuggestionProvider> dispatcher) throws Exception {
        LiteralArgumentBuilder<ClientSuggestionProvider> clientCommand = cLiteral("clientcommand");
        MoreCommandsClient.getNodes().forEach((cmd, nodes) -> nodes.forEach(node -> clientCommand
                .then(cLiteral(node.getName())
                        .executes(ctx -> open("/commands/client" + (cmd.getDocsPath().startsWith("/") ? "" : "/") + cmd.getDocsPath())))));

        LiteralArgumentBuilder<ClientSuggestionProvider> command = cLiteral("command");
        MoreCommands.getNodes().forEach((cmd, nodes) -> nodes.forEach(node -> command
                .then(cLiteral(node.getName())
                        .executes(ctx -> open("/commands/server" + (cmd.getDocsPath().startsWith("/") ? "" : "/") + cmd.getDocsPath())))));

        LiteralArgumentBuilder<ClientSuggestionProvider> gamerule = cLiteral("gamerule");
        IMoreGameRules.get().allRules().forEach((name, key) -> gamerule
                .then(cLiteral(name)
                        .executes(ctx -> open("/gamerules/" + hyphenCase(name)))));

        LiteralArgumentBuilder<ClientSuggestionProvider> clientOption = cLiteral("clientoption");
        ClientOption.getKeyMappedOptions().forEach((key, option) -> clientOption
                .then(cLiteral(key)
                        .executes(ctx -> open("/client-options/" + option.getCategory().name().toLowerCase(Locale.ROOT).replace('_', '-') + '/' +
                                option.getName().toLowerCase(Locale.ROOT).replace(' ', '-')))));

        dispatcher.register(cLiteral("mcdocs")
                .then(clientCommand)
                .then(command)
                .then(gamerule)
                .then(clientOption));
    }

    @Override
    public String getDocsPath() {
        return "/docs";
    }

    @Override
    public boolean doLateInit() {
        // This has to be registered after all commands have been registered.
        return true;
    }

    private static int open(String path) {
        Util.getPlatform().openUri("https://morecommands.ptsmods.com" + path);
        return 1;
    }

    private static String hyphenCase(String camelCase) {
        StringBuilder sb = new StringBuilder();
        for (char c : camelCase.toCharArray()) {
            if (Character.isUpperCase(c))
                sb.append('-').append(Character.toLowerCase(c));
            else sb.append(c);
        }

        return sb.toString();
    }
}

@@ -430,33 +430,8 @@
 nd;%0A
-import java.util.Locale;%0A
 impo
@@ -520,16 +520,42 @@
 vider;%0A%0A
+import java.util.Locale;%0A%0A
 public c
@@ -2248,16 +2248,59 @@
 cdocs%22)%0A
+                .executes(ctx -%3E open(%22%22))%0A
         

Make mcdocs command refer to the docs if no args were passed