Skip to content

Commit

Permalink
Generate command list debug in MD instead of a text list
Browse files Browse the repository at this point in the history
  • Loading branch information
Ale32bit committed Dec 28, 2024
1 parent 66437ad commit 910018e
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package me.alexdevs.solstice.modules.core.commands;

import com.mojang.brigadier.LiteralMessage;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import me.alexdevs.solstice.Solstice;
import me.alexdevs.solstice.api.events.SolsticeEvents;
Expand All @@ -19,6 +16,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -84,21 +82,26 @@ public LiteralArgumentBuilder<ServerCommandSource> command(String name) {
.executes(context -> {
var builder = new StringBuilder();

builder.append(String.format("%s; %s; %s; %s\n", "Module", "Command", "Aliases", "Permission"));
for(var command : Debug.commandDebugList) {
builder.append(String.format("%s; %s; %s; %s\n", command.module(), command.command(), String.join(" ", command.commands()), command.permission()));
var list = new ArrayList<>(Debug.commandDebugList);

list.sort(Comparator.comparing(Debug.CommandDebug::module));

builder.append(String.format("| %s | %s | %s | %s |\n", "Module", "Command", "Aliases", "Permission"));
builder.append("|---|---|---|---|\n");
for (var command : list) {
builder.append(String.format("| %s | %s | %s | %s |\n", command.module(), command.command(), String.join(" ", command.commands()), command.permission()));
}

var output = builder.toString();

var file = FabricLoader.getInstance().getGameDir().resolve("solstice-commands.txt").toFile();
var file = FabricLoader.getInstance().getGameDir().resolve("solstice-commands.md").toFile();
try (var fw = new FileWriter(file)) {
fw.write(output);
} catch (IOException e) {
throw new SimpleCommandExceptionType(Text.of(e.getMessage())).create();
}

context.getSource().sendFeedback(() -> Text.of("Generated 'solstice-commands.txt'"), true);
context.getSource().sendFeedback(() -> Text.of("Generated 'solstice-commands.md'"), true);

return 1;
}))
Expand Down

0 comments on commit 910018e

Please sign in to comment.