-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirected command needs to have arguments #46
Comments
I had the same issue. I was able to get around it by doing the following: public static void register(CommandDispatcher<MessageContext> dispatcher) {
LiteralArgumentBuilder<MessageContext> builder = Commands.literal("!online").executes((command) -> {
return sendResponse(command.getSource());
});
dispatcher.register(builder);
dispatcher.register(Commands.literal("!o").executes(builder.getCommand()));
} |
See https://github.com/VelocityPowered/Velocity/blob/8abc9c80a69158ebae0121fda78b55c865c0abad/proxy/src/main/java/com/velocitypowered/proxy/util/BrigadierUtils.java#L38 for a brute-force solution. Gamebuster's solution is incomplete and only works for nodes with no children. Note that this is not a proper fix. |
Still no official solution on this? I'd love it if I could just register multiple literals for LiteralArgumentBuilder |
Makes parseNodes consider the Command of a redirect target when no contents can be read. For example, given a "foo" literal with a non-null Command, and a "bar" literal forwarding to the "foo" node, the parse results' context contains the command of the "foo" node, and the parsed node is the "bar" node. This follows the same logic as a regular redirect. CommandDispatcherTest#testExecuteRedirectedMultipleTimes highlights the parse tree contains the redirected node (`redirectNode`), while the executed Command is that of the target node (`concreteNode`). Fixes Mojang#46
Makes parseNodes consider the Command of a redirect target when no contents can be read. For example, given a "foo" literal with a non-null Command, and a "bar" literal forwarding to the "foo" node, the parse results' context contains the command of the "foo" node, and the parsed node is the "bar" node. This follows the same logic as a regular redirect. `CommandDispatcherTest#testExecuteRedirectedMultipleTimes` highlights the parse tree contains the redirected node (`redirectNode`), while the executed Command is that of the target node (`concreteNode`). Fixes Mojang#46
Makes parseNodes consider the Command of a redirect target when no contents can be read. For example, given a "foo" literal with a non-null Command, and a "bar" literal forwarding to the "foo" node, the parse results' context contains the command of the "foo" node, and the parsed node is the "bar" node. This follows the same logic as a regular redirect. `CommandDispatcherTest#testExecuteRedirectedMultipleTimes` highlights the parse tree contains the redirected node (`redirectNode`), while the executed Command is that of the target node (`concreteNode`). Fixes Mojang#46
Could this be fixed? |
still happening. bump |
Any ETA? Will this ever be picked up? |
Consider the following situation: val node = dispatcher.register(literal("foo") .then(argument("arg", StringArgumentType.string()) .executes { ChatLib.chat("foo with arg") 1 }) .executes { ChatLib.chat("foo without arg") 1 }) dispatcher.register(literal("bar").redirect(node)) With this setup, "/bar test" will work as expected, however "/bar" will fail! Redirect nodes currently do not consider the command of the node they redirect to, only their children. As the comment is this Mixin indicates, this is more of a band-aid fix than a proper one since any redirect modifiers used in the redirect() call will be ignored if there are no arguments following the redirection. This isn't so important for the purposes of the CT-provided API, but may affect commands from other mods. We'll have to keep an eye on this and address it if it becomes a problem. Relevant issue: Mojang/brigadier#46
would be nice to have that fixed or have someone comment if this is intentional behaviour |
Maybe try this solution: #137 |
Problem
I wanted to make an alias for a command, so I registered a node that just redirected to my target, which worked nicely if the target command had arguments.
MWE
Expected result
Actual result
Small analysis
It looks like this might be by design, if so documenting it would be nice (or a RTFM link :)
If am not mistaken the reason reason for this is as follows:
Line (1) prevents the command from being parsed correctly, as the input ends after the literal of the redirected command. This is also the line that makes me think it might be deliberate.
You'd need to change that
1
to0
in the first if and special case the case when the reader can not read anymore. Additionally you need to take care that the child context is correctly set, so that redirect modifiers work.Further remarks
Line (1) could also hint at somebody just wanting to require an argument separator behind a redirected command and allow it to have no arguments, but that has a few flaws:
parseNodes
call (2) fails. This leads to the current context having the wrong node, and the child context having no nodes.This context is then passed on to execute, which does the following:
contexts
is not empty and enters the loopif(child != null)
if(child.hasNodes())
, which will be false, as outlined above - it didn't match anything in the recursive callnext
to be skipped,commandFound
is not set and the outer while loop exists, ascontexts
is set tonext
which means tonull
.Closing remarks
I think that wall of text can be summed up with a few lines:
Thank you for reading up until here :)
The text was updated successfully, but these errors were encountered: