Skip to content
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

Literal argument aliases are ignored by cloud-brigadier #88

Closed
metabrixkt opened this issue Aug 2, 2024 · 1 comment
Closed

Literal argument aliases are ignored by cloud-brigadier #88

metabrixkt opened this issue Aug 2, 2024 · 1 comment

Comments

@metabrixkt
Copy link

Steps to reproduce

Here's an example command:

manager.command(
    manager
        .commandBuilder("reputation", Description.of("Change player's reputation"))
        .permission("example-plugin.command.reputation.good")
        .senderType(Player.class)
        .required("player", offlinePlayerParser())
        .literal("good", "potato", "tomato")
        .handler(new AsyncHandler<>(ctx -> handleAddRemove(ctx.sender(), ctx.get("player"), ReputationAction.UPVOTE)))
);

Expected behavior

Expected command tree:

literal "reputation"
    offline player "player"
        literal "good"
        literal "potato"
        literal "tomato"

Observed behavior

However, the resulting Brigadier command tree looks like this:

literal "reputation"
    offline player "player"
        literal "good"

Other

I might be wrong, but I think this happens because o.i.c.brigadier.node.LiteralBrigadierNodeFactory#constructCommandNode(CommandNode<C>, BrigadierPermissionChecker<C>, com.mojang.brigadier.Command<S>) creates a literal node for the component name only, ignoring its aliases:

final ArgumentBuilder<S, ?> argumentBuilder;
if (root.component().type() == CommandComponent.ComponentType.LITERAL) {
    argumentBuilder = this.createLiteralArgumentBuilder(root.component(), root, permissionChecker);
} else {
    argumentBuilder = this.createVariableArgumentBuilder(root.component(), root, permissionChecker);
}
this.updateExecutes(argumentBuilder, root, executor);

And then in LiteralBrigadierNodeFactory#createLiteralArgumentBuilder(CommandComponent<C>, CommandNode<C>, BrigadierPermissionChecker<C>):

private @NonNull ArgumentBuilder<S, ?> createLiteralArgumentBuilder(
        final @NonNull CommandComponent<C> component,
        final @NonNull CommandNode<C> root,
        final @NonNull BrigadierPermissionChecker<C> permissionChecker
) {
    return LiteralArgumentBuilder.<S>literal(component.name()) // <--- aliases not used
            .requires(this.requirement(root, permissionChecker));
}

One possible fix would be making constructCommandNode(...) return a list of ArgumentBuilders which would work well with Brigadier node's then(...) method

But I might be completely wrong about why this happens, so ¯\_(ツ)_/¯

It could also be related to #5

@jpenilla
Copy link
Member

jpenilla commented Aug 2, 2024

Duplicate #5

@jpenilla jpenilla closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants