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

Pattern matching where literals are mixed with arguments #137

Closed
bergerkiller opened this issue Nov 16, 2020 · 2 comments
Closed

Pattern matching where literals are mixed with arguments #137

bergerkiller opened this issue Nov 16, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@bergerkiller
Copy link
Contributor

bergerkiller commented Nov 16, 2020

I don't know if this is a bug, something that is purposefully not implemented, or something I could work around using annotations I've missed in the documentation.

I have two commands declared:

    @CommandMethod("command literal")
    @CommandDescription("Performs the literal operation")
    private void commandLiteral(
              final CommandSender sender
    ) {
        sender.sendMessage("Performed command with a literal match");
    }

    @CommandMethod("command <argument>")
    @CommandDescription("Performs the operation with some variable")
    private void commandArgument(
              final CommandSender sender,
              final @Argument(value="argument") String argument
    ) {
        sender.sendMessage("Performed command using " + argument);
    }

But get the error:

com.bergerkiller.bukkit.tc.dep.cloud.exceptions.AmbiguousNodeException: Ambiguous Node: argument cannot be added as a child to command (All children: literal, argument)
    at com.bergerkiller.bukkit.tc.dep.cloud.CommandTree.checkAmbiguity(CommandTree.java:741)
    at java.lang.Iterable.forEach(Iterable.java:75)
    at com.bergerkiller.bukkit.tc.dep.cloud.CommandTree.checkAmbiguity(CommandTree.java:745)
    at com.bergerkiller.bukkit.tc.dep.cloud.CommandTree.verifyAndRegister(CommandTree.java:672)
    at com.bergerkiller.bukkit.tc.dep.cloud.CommandTree.insertCommand(CommandTree.java:617)
    at com.bergerkiller.bukkit.tc.dep.cloud.CommandManager.command(CommandManager.java:210)
    at com.bergerkiller.bukkit.tc.dep.cloud.annotations.AnnotationParser.parse(AnnotationParser.java:250)

I want /command literal to match one, and have /command anythingelse match the other. Obviously I can handle this by doing an equals check of the argument, but let's assume there are a lot of literals like this. Or that some literals have flags, while the variable one doesn't.

Is there a solution?

@jpenilla
Copy link
Member

An AmbiguousNodeException is thrown here because by cloud's definition, those nodes are ambiguous. A node can have multiple literals, or a single argument as children. See #130 and #106 for further context.

@bergerkiller
Copy link
Contributor Author

Got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants