Open DevSolaris opened 2 months ago
Contexts are linked. Use getLastChild() on the context in the suggestion provider to get the correct context to get the parsed argument.
Yeah, this is a combination of how Brigadier behaves (Mojang/brigadier#142) and how Paper registers commands.
When you register a command through Paper's Commands#register
, the main label ("testcommand"
here) gets registered as a redirect to the namespaced node ("brigadiertest:testcommand"
for example). When a command redirects, Brigadier puts future arguments into a child CommandContext
. So, to access the previous arguments in the SuggestionProvider, you need to call CommandContext.getLastChild()#getArgument
.
On the other hand, using Commands.getDispatcher()#register
does not create a redirected node, which is why the command you gave under Other
works. Note that this command can still generate suggestions in a redirected situation using /execute run testcommand...
, so it can help to call CommandContext#getLastChild
anyway.
Expected behavior
I expect this code to work and to give the "config" argument
Observed/Actual behavior
Steps/models to reproduce
Type
testcommand copy config1
and press tabPlugin and Datapack List
Just this test plugin, no datapacks
Paper version
Other
When registering the same command using the dispatcher, code below, it does work fine and the tab complete works