question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a greedy "list argument"

See original GitHub issue

From #275.

Please describe your suggestion Allowing users to enter a list of values is very useful. WorldEdit has a nice implementation of a list argument, where users can provide a list of materials to manipulate blocks: worldedit

Implementing this “properly” is outside of the basic scope of the CommandAPI for now (see regex argument mod), however we can “simulate” a list argument by using an underlying GreedyStringArgument with a powerful suggestion provider.

Work for this has already begun on the dev/listargument branch.

Formally, we need to support:

  • Providing a list of values for the list
  • Ensuring that the inputs to the argument don’t accept values outside of the provided list (e.g. a list [apple, banana, cat] can’t (or won’t) accept dirt as a value)
  • Allowing users to provide tooltips to entries
  • Allowing users to specify a delimiter (e.g. a comma vs a space)
  • The casting type should be a Collection parameterized over some type T which is provided by the users

Please supply examples of the desired inputs and outputs Example: Input: Using the following code:

List<String> list = List.of("apple", "banana", "cat", "dog", "elephant");
new CommandAPICommand("blah")
    .withArguments(new ListArgumentBuilder<String>("node", " ").withList(list).withStringMapper().build())
    .executes((sender, args) -> {
        Collection<String> myList = (Collection<String>) args[0];
        sender.sendMessage("Provided: " + myList);
    })
    .register();

new CommandAPICommand("blahcomma")
.withArguments(new ListArgumentBuilder<String>("node", ",").withList(list).withStringMapper().build())
.executes((sender, args) -> {
    Collection<String> myList = (Collection<String>) args[0];
    sender.sendMessage("Provided: " + myList);
})
.register();

Output: Typing a command can accept a list of arguments:

listargument

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
SNWCreationscommented, May 8, 2022

I’m looking forward to this update. 😃 👍

0reactions
SNWCreationscommented, May 29, 2022

Implemented in 8.2.0.

@SNWCreations Yes, dynamic lists are supported, you can read all about it in the 8.2.0 documentation for list arguments here: https://commandapi.jorel.dev/8.2.0/listarguments.html

Thank you! I will upgrade my project in future. (I am too busy now.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basics of Greedy Algorithms Tutorials & Notes - HackerEarth
Detailed tutorial on Basics of Greedy Algorithms to improve your understanding of Algorithms. Also try practice problems to test & improve your skill...
Read more >
using greedy algorithm search in lists - prolog - Stack Overflow
using greedy algorithm search in lists ... Given a list of positive integer Items whose elements are guaranteed to be in sorted ascending...
Read more >
Greedy Algorithm Explained using LeetCode Problems
Show that if we make the greedy choice, then only one subproblem remains. Validate the rightness of the greedy choice.
Read more >
Greedy Algorithms
This argument implies by induction that some optimal solution contains the entire greedy solution, and therefore equals the greedy solution.
Read more >
Greedy Algorithms
Lemma 1: The greedy algorithm always finds a path from the start lilypad to the destination lilypad. Proof: By contradiction; suppose it did...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found