forked from chipmunkmc/chipmunkbot
add description to commands
yes i need to modify brigaydier to do this
This commit is contained in:
parent
d6f68cd2fa
commit
9a55cd11f4
11 changed files with 43 additions and 17 deletions
2
pom.xml
2
pom.xml
|
@ -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>
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,11 +27,12 @@ public class HelpCommand {
|
|||
|
||||
dispatcher.register(
|
||||
literal("help")
|
||||
.executes(instance::sendCommandList)
|
||||
.then(
|
||||
argument("command", greedyString())
|
||||
.executes(instance::sendUsage)
|
||||
)
|
||||
.describe(ComponentMessage.wrap(Component.text("Shows the help")))
|
||||
.executes(instance::sendCommandList)
|
||||
.then(
|
||||
argument("command", greedyString())
|
||||
.executes(instance::sendUsage)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -42,6 +42,7 @@ public class MusicCommand {
|
|||
|
||||
dispatcher.register(
|
||||
literal("music")
|
||||
.describe(ComponentMessage.wrap(Component.text("Play musics")))
|
||||
.then(
|
||||
literal("play")
|
||||
.then(
|
||||
|
|
|
@ -22,10 +22,11 @@ public class NetMsgCommand {
|
|||
|
||||
dispatcher.register(
|
||||
literal("netmsg")
|
||||
.then(
|
||||
argument("message", greedyString())
|
||||
.executes(instance::netmsg)
|
||||
)
|
||||
.describe(ComponentMessage.wrap(Component.text("Broadcasts a message to every server")))
|
||||
.then(
|
||||
argument("message", greedyString())
|
||||
.executes(instance::netmsg)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ public class ReconnectCommand {
|
|||
|
||||
dispatcher.register(
|
||||
literal("reconnect")
|
||||
.executes(instance::reconnect)
|
||||
.describe(ComponentMessage.wrap(Component.text("Reconnects the bot")))
|
||||
.executes(instance::reconnect)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,10 +20,11 @@ public class RunCommand {
|
|||
|
||||
dispatcher.register(
|
||||
literal("run")
|
||||
.then(
|
||||
argument("command", greedyString())
|
||||
.executes(instance::run)
|
||||
)
|
||||
.describe(ComponentMessage.wrap(Component.text("Runs a command in the command core and return its output")))
|
||||
.then(
|
||||
argument("command", greedyString())
|
||||
.executes(instance::run)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -12,7 +12,8 @@ public class TestCommand {
|
|||
|
||||
dispatcher.register(
|
||||
literal("test")
|
||||
.executes(instance::helloWorld)
|
||||
.describe(ComponentMessage.wrap(Component.text("Tests if the bot is online/working")))
|
||||
.executes(instance::helloWorld)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue