commands icon indicating copy to clipboard operation
commands copied to clipboard

Command completion mixing @players with "enum" values

Open devmattrick opened this issue 6 years ago • 6 comments

I'm trying create a slightly improved version of the vanilla /gamemode command. This, unfortunately appears to break tab completion in a way. The gamemode command should operate as follows:

  • /gamemode creative - Sets the executor's gamemode to creative
  • /gamemode Dinnerbone - Toggle's Dinnerbone's gamemode between creative and survival

Ideally, the tab completion when typing /gamemode should both suggest online players and the actual valid gamemode ids (survival, creative, etc.). This is what I attempted to use to achieve this:

@Default
@CommandCompletion("@players|survival|creative|adventure|spectator")
public void setOwnOrToggleOtherGameMode(Player player, @Single String arg) {
    // ...
}

This, however makes the tab completion only suggest online players; the options for the game mode ids are no suggested at all.

I also had these separated into two different methods (one designed to only handle online players and the other designed to handle toggling the executor's game mode), but while they both worked, it again only suggested online players and not the game mode ids.

devmattrick avatar Jan 04 '20 03:01 devmattrick

Shouldn't this be possible with two command methods and different args (and thus completions)?

MiniDigger avatar Jan 04 '20 09:01 MiniDigger

@MiniDigger I tried with multiple command methods, but it still only suggested players. In fact, now that I'm looking at it, it seems that other methods are conflicting with each other:

@Default
public void toggleOwnGameMode(Player player) {
    // ...
}

@Default
@CommandCompletion("survival|creative|adventure|spectator")
public void setOwnGameMode(Player player, @Single String arg) {
    // ...
}

@Default
@CommandCompletion("@players")
public void toggleOtherGameMode(Player player, @Single String arg) {
    // ...
}

@Default
@CommandCompletion("@players survival|creative|adventure|spectator")
public void setOtherGameMode(Player player, @Single String playerName, @Single String arg) {
    // ...
}

Upon typing /gamemode, the only suggestions are online player names.

devmattrick avatar Jan 04 '20 23:01 devmattrick

The signature from "setOwnGameMode" and "toggleOtherGameMode" is the same. Acf can't know which method is the "right" one for executing this. Try to remove the method "toggleOtherGameMode", you should see the command completions then

Joo200 avatar Jan 04 '20 23:01 Joo200

@JOO200 as mentioned in the original issue, I tried merging those two methods together. It still only suggests player names.

After doing more testing, it appears that its actually setOtherGameMode that's causing this issue. It is overriding all other suggestions and as such it only suggests player names. So changing it to @players|survival|creative|adventure|spectator survival|creative|adventure|spectator makes it almost work as intended, but feels a bit wrong because that method isn't designed to handle those arguments. It also results in being able to do this: image

So ideally, each @CommandCompletion should be merged and future suggestions should only be suggested if the previous one matches. Not sure if this is something that you're willing to change since this seems like an edge case.

devmattrick avatar Jan 05 '20 00:01 devmattrick

Why do all your methods have @default?

MiniDigger avatar Jan 05 '20 09:01 MiniDigger

@MiniDigger because none of them are subcommands, since they can take up to 2 dynamic arguments. Not sure if it'd be better just make it all one giant method but in that case the autocomplete would still exhibit the same behavior as my previous comment.

devmattrick avatar Jan 05 '20 12:01 devmattrick