Hello developers,
I am currently playing around with the new Brigadier Commands and want to create Commands with Mojang like Tooltips and Tab Completion. My results were close, but not nearly as good as the ones from Mojang directly. I know there’s a difference between commands from velocity and from spigot, but it has to be doable to get the same result.
Let’s use the /effect
command as example.
The command takes to Required Arguments, either give
or clear
. If you input let’s say a c
, of course only clear
gets suggested. I already got this behavior working, maybe not smart, but working.
BUT if you input e.g. a
, there is an error message appearing and the input gets marked red. In my implementation, it just suggests both arguments aigan.
This is what I can not recreate right now, I don’t have any approach, to set static Argument Possibilities.
There’s one more thing I am unable to recreate. Let’s use the /effect
command again.
If you input something which is not suggested, a tooltip is shown with the correct Syntax.
I tried using the SuggestionsBuilder#suggest(String text, Message tooltip)
but never got any tooltip displayed.
Let’s work it out on this snippet:
private static final String[] POSSIBLE_ARGS = {"info","out"};
public void register() {
LiteralCommandNode<CommandSource> totalNode = LiteralArgumentBuilder
.<CommandSource>literal("test")
.executes(context -> {
context.getSource().sendMessage(Component.text("global node"));
return 1;
}).build();
ArgumentCommandNode<CommandSource,String> argNode = RequiredArgumentBuilder
.<CommandSource,String>argument("arg", StringArgumentType.word())
.suggests((context, builder) -> {
//TODO add suggestion handling
return builder.buildFuture();
}).build();
totalNode.addChild(argNode);
getServer().getCommandManager().register(new BrigadierCommand(totalNode));
}