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>
|
<dependency>
|
||||||
<groupId>com.mojang</groupId>
|
<groupId>com.mojang</groupId>
|
||||||
<artifactId>brigadier</artifactId>
|
<artifactId>brigadier</artifactId>
|
||||||
<version>1.0.18</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ public class EchoCommand {
|
||||||
|
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
literal("echo")
|
literal("echo")
|
||||||
|
.describe(ComponentMessage.wrap(Component.text("Echoes a message")))
|
||||||
.then(
|
.then(
|
||||||
argument("text", greedyString())
|
argument("text", greedyString())
|
||||||
.executes(instance::echo)
|
.executes(instance::echo)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package land.chipmunk.chipmunkbot.commands;
|
package land.chipmunk.chipmunkbot.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Message;
|
||||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||||
import land.chipmunk.chipmunkbot.Configuration;
|
import land.chipmunk.chipmunkbot.Configuration;
|
||||||
import land.chipmunk.chipmunkbot.command.*;
|
import land.chipmunk.chipmunkbot.command.*;
|
||||||
|
@ -26,11 +27,12 @@ public class HelpCommand {
|
||||||
|
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
literal("help")
|
literal("help")
|
||||||
.executes(instance::sendCommandList)
|
.describe(ComponentMessage.wrap(Component.text("Shows the help")))
|
||||||
.then(
|
.executes(instance::sendCommandList)
|
||||||
argument("command", greedyString())
|
.then(
|
||||||
.executes(instance::sendUsage)
|
argument("command", greedyString())
|
||||||
)
|
.executes(instance::sendUsage)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +89,7 @@ public class HelpCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component generateUsages (Configuration config, CommandDispatcher dispatcher, CommandNode<CommandSource> node) {
|
public Component generateUsages (Configuration config, CommandDispatcher dispatcher, CommandNode<CommandSource> node) {
|
||||||
|
final List<Component> components = new ArrayList<>();
|
||||||
final List<Component> usages = new ArrayList<>();
|
final List<Component> usages = new ArrayList<>();
|
||||||
|
|
||||||
for (String usage : dispatcher.getAllUsage(node, null, true)) {
|
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(
|
dispatcher.register(
|
||||||
literal("info")
|
literal("info")
|
||||||
|
.describe(ComponentMessage.wrap(Component.text("Shows the info about the bot")))
|
||||||
.executes(instance::sendBotInfo)
|
.executes(instance::sendBotInfo)
|
||||||
.then(
|
.then(
|
||||||
literal("server")
|
literal("server")
|
||||||
|
|
|
@ -38,6 +38,7 @@ public class LogQueryCommand {
|
||||||
|
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
literal("logquery")
|
literal("logquery")
|
||||||
|
.describe(ComponentMessage.wrap(Component.text("Queries the bots log files")))
|
||||||
.then(
|
.then(
|
||||||
literal("abort")
|
literal("abort")
|
||||||
.executes(instance::abortCommand)
|
.executes(instance::abortCommand)
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class MusicCommand {
|
||||||
|
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
literal("music")
|
literal("music")
|
||||||
|
.describe(ComponentMessage.wrap(Component.text("Play musics")))
|
||||||
.then(
|
.then(
|
||||||
literal("play")
|
literal("play")
|
||||||
.then(
|
.then(
|
||||||
|
|
|
@ -22,10 +22,11 @@ public class NetMsgCommand {
|
||||||
|
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
literal("netmsg")
|
literal("netmsg")
|
||||||
.then(
|
.describe(ComponentMessage.wrap(Component.text("Broadcasts a message to every server")))
|
||||||
argument("message", greedyString())
|
.then(
|
||||||
.executes(instance::netmsg)
|
argument("message", greedyString())
|
||||||
)
|
.executes(instance::netmsg)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ public class ReconnectCommand {
|
||||||
|
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
literal("reconnect")
|
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(
|
dispatcher.register(
|
||||||
literal("run")
|
literal("run")
|
||||||
.then(
|
.describe(ComponentMessage.wrap(Component.text("Runs a command in the command core and return its output")))
|
||||||
argument("command", greedyString())
|
.then(
|
||||||
.executes(instance::run)
|
argument("command", greedyString())
|
||||||
)
|
.executes(instance::run)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||||
import land.chipmunk.chipmunkbot.command.CommandSource;
|
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.getString;
|
||||||
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
|
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
|
||||||
|
@ -16,6 +18,7 @@ public class SayCommand {
|
||||||
|
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
literal("say")
|
literal("say")
|
||||||
|
.describe(ComponentMessage.wrap(Component.text("Makes the bot say a message")))
|
||||||
.then(
|
.then(
|
||||||
argument("message", greedyString())
|
argument("message", greedyString())
|
||||||
.executes(instance::say)
|
.executes(instance::say)
|
||||||
|
|
|
@ -12,7 +12,8 @@ public class TestCommand {
|
||||||
|
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
literal("test")
|
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