add description to commands

yes i need to modify brigaydier to do this
This commit is contained in:
Chayapak 2023-06-11 20:29:35 +07:00
parent d6f68cd2fa
commit 9a55cd11f4
11 changed files with 43 additions and 17 deletions

View file

@ -48,7 +48,7 @@
<dependency>
<groupId>com.mojang</groupId>
<artifactId>brigadier</artifactId>
<version>1.0.18</version>
<version>1.1.0-SNAPSHOT</version>
</dependency>
</dependencies>

View file

@ -16,6 +16,7 @@ public class EchoCommand {
dispatcher.register(
literal("echo")
.describe(ComponentMessage.wrap(Component.text("Echoes a message")))
.then(
argument("text", greedyString())
.executes(instance::echo)

View file

@ -1,5 +1,6 @@
package land.chipmunk.chipmunkbot.commands;
import com.mojang.brigadier.Message;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.Configuration;
import land.chipmunk.chipmunkbot.command.*;
@ -26,6 +27,7 @@ public class HelpCommand {
dispatcher.register(
literal("help")
.describe(ComponentMessage.wrap(Component.text("Shows the help")))
.executes(instance::sendCommandList)
.then(
argument("command", greedyString())
@ -87,6 +89,7 @@ public class HelpCommand {
}
public Component generateUsages (Configuration config, CommandDispatcher dispatcher, CommandNode<CommandSource> node) {
final List<Component> components = new ArrayList<>();
final List<Component> usages = new ArrayList<>();
for (String usage : dispatcher.getAllUsage(node, null, true)) {
@ -103,6 +106,18 @@ public class HelpCommand {
);
}
return Component.join(JoinConfiguration.separator(Component.newline()), usages);
final Message description = node.getDescription();
components.add(
Component.translatable(
"%s - %s",
Component.text(node.getName()).color(TextColor.fromHexString(config.color().primary())),
Component.text(description == null ? "No description" : description.getString()).color(NamedTextColor.GRAY)
).color(NamedTextColor.DARK_GRAY)
);
components.add(Component.join(JoinConfiguration.separator(Component.newline()), usages));
return Component.join(JoinConfiguration.separator(Component.newline()), components);
}
}

View file

@ -28,6 +28,7 @@ public class InfoCommand {
dispatcher.register(
literal("info")
.describe(ComponentMessage.wrap(Component.text("Shows the info about the bot")))
.executes(instance::sendBotInfo)
.then(
literal("server")

View file

@ -38,6 +38,7 @@ public class LogQueryCommand {
dispatcher.register(
literal("logquery")
.describe(ComponentMessage.wrap(Component.text("Queries the bots log files")))
.then(
literal("abort")
.executes(instance::abortCommand)

View file

@ -42,6 +42,7 @@ public class MusicCommand {
dispatcher.register(
literal("music")
.describe(ComponentMessage.wrap(Component.text("Play musics")))
.then(
literal("play")
.then(

View file

@ -22,6 +22,7 @@ public class NetMsgCommand {
dispatcher.register(
literal("netmsg")
.describe(ComponentMessage.wrap(Component.text("Broadcasts a message to every server")))
.then(
argument("message", greedyString())
.executes(instance::netmsg)

View file

@ -13,6 +13,7 @@ public class ReconnectCommand {
dispatcher.register(
literal("reconnect")
.describe(ComponentMessage.wrap(Component.text("Reconnects the bot")))
.executes(instance::reconnect)
);
}

View file

@ -20,6 +20,7 @@ public class RunCommand {
dispatcher.register(
literal("run")
.describe(ComponentMessage.wrap(Component.text("Runs a command in the command core and return its output")))
.then(
argument("command", greedyString())
.executes(instance::run)

View file

@ -4,6 +4,8 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.command.CommandSource;
import land.chipmunk.chipmunkbot.command.ComponentMessage;
import net.kyori.adventure.text.Component;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
@ -16,6 +18,7 @@ public class SayCommand {
dispatcher.register(
literal("say")
.describe(ComponentMessage.wrap(Component.text("Makes the bot say a message")))
.then(
argument("message", greedyString())
.executes(instance::say)

View file

@ -12,6 +12,7 @@ public class TestCommand {
dispatcher.register(
literal("test")
.describe(ComponentMessage.wrap(Component.text("Tests if the bot is online/working")))
.executes(instance::helloWorld)
);
}