Skip to content

Hey there! If you like my work, you can support me by sponsoring me on GitHub. Thanks! ❤

Sponsor me
on GitHub

@Varargs

If you want to define an argument that can accept list of values, you can use the @Varargs annotation.

Supported collection types:

Collection TypeSupported Types
arrayT[], T...
listList<T>, ArrayList<T>, LinkedList<T>
setSet<T>, HashSet<T>, LinkedHashSet<T>, NavigableSet<T>, TreeSet<T>
queueQueue<T>, Deque<T>, ArrayDeque<T>, PriorityQueue<T>
vectorVector<T>, Stack<T>
-Collection<T>

Example

For example, you can create a command that gets a list of players and checks their health:

java
@Command(name = "check-health")
public class CheckHealthCommand {
    @Execute
    void checkHealth(@Context CommandSender sender, @Varargs Player... players) {
        for (Player player : players) {
            double health = player.getHealth();
            sender.sendMessage(player.getName() + " has " + health + " health");
        }
    }
}

Made by LiteDevelopers and Contributors with ❤️