Incendo / cloud

Command framework & dispatcher for the JVM
https://cloud.incendo.org
MIT License
432 stars 54 forks source link

Allow ambiguous nodes #780

Closed MelonHell closed 1 week ago

MelonHell commented 1 week ago

Why can't I do this? Using Either is very inconvenient

For example, when using Either, you cannot specify different permissions. And Either only supports two types, but what if you need more?

    @Command("tptest <pos>")
    @Permission("command.tptest.pos")
    fun tptestCommand(
        sender: Player,
        pos: Pos,
    ) {
        //
    }

    @Command("tptest <player>")
    @Permission("command.tptest.player")
    fun tptestCommand(
        sender: Player,
        player: Player,
    ) {
        //
    }
Caused by: org.incendo.cloud.exception.AmbiguousNodeException: Ambiguous Node: player cannot be added as a child to tptest (All children: player, pos)
    at org.incendo.cloud.CommandTree.checkAmbiguity(CommandTree.java:1173)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
    at org.incendo.cloud.CommandTree.checkAmbiguity(CommandTree.java:1204)
    at org.incendo.cloud.CommandTree.verifyAndRegister(CommandTree.java:1063)
    at org.incendo.cloud.CommandTree.insertCommand(CommandTree.java:993)
    at org.incendo.cloud.CommandManager.command(CommandManager.java:244)
    at org.incendo.cloud.annotations.AnnotationParser.parse(AnnotationParser.java:762)

Vanilla Minecraft has support for ambiguous nodes and it is very convenient, for example the teleport command image

masmc05 commented 1 week ago

The vanilla one is not "supporting", you can find on mojira lots of bugs related to those commands because even brigadier doesn't support this, but they just didn't add a prevention of doing this unsupported behavior

jpenilla commented 1 week ago

And Either only supports two types, but what if you need more?

Then you can write your own parser that disambiguates.

Not supporting ambiguous tree structures is an intentional design decision that we will not be changing.