Brigadier usage

Discussion in 'Spigot Plugin Development' started by MrIvanPlays, May 24, 2019.

  1. I have looked at @Luck's library about it, but still can't understand how to check on what command argument i am currently. Someone help. Thanks
     
  2. Please explain what you're trying to do.
     
    • Agree Agree x 1
  3. Suggestion for <message> which is at argument 2 of the command. How do i check on what argument i am with brigadier?
     
  4. I know this isn't normal, but please use your native language instead of English. It might work better.
     
    • Optimistic Optimistic x 1
  5. Ok let me just use normal tab completion for example.

    Code (Java):
    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
        List<String> matches = new ArrayList<>();
        if (args.length == 1) { // how do i check that with brigadier
            matches.add("something");
        }
        if (args.length == 2) { // how do i check that with brigadier
            matches.add("otherthing");
        }
        return matches;
    }
     
     
  6. As far as I can tell, in brigadier you know where you are because you provide a lambda for that specific argument. Therefor it's a bit different to the bukkit way since you don't handle all cases in one method, but instead have separate "providers" for each argument.

    Take this as an example:

    Code (Text):
    CommandDispatcher<CommandSourceStack> dispatcher = new CommandDispatcher<>();

    dispatcher.register(
        literal("foo")
            .then(
                argument("message", string())
                    .suggests((context,builder) -> {
                        // Here you _know_ that you're handling the suggestions for the "message" argument.
                    })
                    .executes(c -> {
                        // ...
                    })
            )
            //...
    );
    (taken mostly from the example on their GH page)


    Given that you haven't provided any more context on this, I can't really give you a better example here.
     
  7. CommandContext.getNodes() should be what you're after. However, I believe there's a better solution to whatever you need it for if you give more context.
     
  8. Ok let me just give you the whole tab completion for the command

    Code (Java):

    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String alias,
                                      String[] args) {
        if (command.getName().equalsIgnoreCase("ae")) {
            if (args.length == 1) {
                return Stream.of("send").filter(a -> a.startsWith(args[0])).collect(Collectors.toList());
            }
            List<String> finalTabCompleter = new ArrayList<>();
            if (sender.hasPermission("announcements.actionbar")) {
                if (args.length == 2) {
                    finalTabCompleter.add("actionbar");
                }
            }
            if (sender.hasPermission("announcements.title")) {
                if (args.length == 2) {
                    finalTabCompleter.add("title");
                }
            }
            if (sender.hasPermission("announcements.broadcast")) {
                if (args.length == 2) {
                    finalTabCompleter.add("broadcast");
                }
            }
            if (sender.hasPermission("announcements.bossbar")) {
                if (args.length == 2) {
                    finalTabCompleter.add("bossbar");
                }
            }
            if (sender.hasPermission("announcements.book")) {
                if (args.length == 2) {
                    finalTabCompleter.add("book");
                }
            }
            if (args.length == 3) {
                // brigadier suggestion: <message>
            }
            return finalTabCompleter.stream().filter(a -> a.startsWith(args[1])).collect(Collectors.toList());
        }
        return null;
    }
    I want this with brigadier.
     
  9. Okx

    Okx

    Are you sure you actually want this with brigadier? If you're writing a normal spigot command, you don't need brigadier.
     
  10. Why not just create separate SuggestionProviders instead of hackily trying to detect the position the argument is at?
     
  11. wat

    Why not? Plus the thing that brigadier allows suggesting things that with bukkit tab competion can't be done.
     
    • Funny Funny x 1
  12. MiniDigger

    Supporter

    You can't just use brigadier for tab completions. You need to let it handle the full command.
     
  13. Okx

    Okx

    You want
    Code (Java):
    org.bukkit.util.StringUtil.copyPartialMatches(args[0], commands, completions);
     
  14. Create two different SuggestionProviders for the 2nd argument and 3rd argument and bind them to each argument separately.

    You can actually, although it's pretty gnarly to do so. :p
     
  15. If you want all the fancy brigadier stuff with error checking and complex tab completion use this here:

    https://github.com/JorelAli/1.13-Command-API

    It supports Custom Arguments you can define and it is clean to get arguments and stuff

    I know its a different API but it's worked well in my experience.
     

Share This Page