Class PlayerListArgument
Expected format: {player1,player2,player3...}
This class handles the parsing of the input string and provides real-time tab-completion suggestions, filtering online player names after each comma or at the start of the list.
- See Also:
-
ArgumentType
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<net.minecraft.server.level.ServerPlayer>getPlayerList(com.mojang.brigadier.context.CommandContext<net.minecraft.commands.CommandSourceStack> context, String name) Retrieves the parsed player argument and resolves it into a collection ofServerPlayerinstances.getPlayerNames(com.mojang.brigadier.context.CommandContext<net.minecraft.commands.CommandSourceStack> context, String name) Retrieves the raw list of player names parsed by this argument.<S> CompletableFuture<com.mojang.brigadier.suggestion.Suggestions>listSuggestions(com.mojang.brigadier.context.CommandContext<S> context, com.mojang.brigadier.suggestion.SuggestionsBuilder builder) parse(com.mojang.brigadier.StringReader stringReader) static PlayerListArgumentplayers()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.mojang.brigadier.arguments.ArgumentType
getExamples
-
Constructor Details
-
PlayerListArgument
public PlayerListArgument()
-
-
Method Details
-
players
-
getPlayerList
public static Collection<net.minecraft.server.level.ServerPlayer> getPlayerList(com.mojang.brigadier.context.CommandContext<net.minecraft.commands.CommandSourceStack> context, String name) Retrieves the parsed player argument and resolves it into a collection ofServerPlayerinstances.This is the preferred method to use when handling this argument in command execution, as it already converts the parsed player names into actual online
ServerPlayerobjects.Only currently online players will be returned. Any names that cannot be resolved to an online player will be ignored.
- Parameters:
context- the command contextname- the name of the argument- Returns:
- a collection of resolved
ServerPlayerobjects
-
getPlayerNames
public static List<String> getPlayerNames(com.mojang.brigadier.context.CommandContext<net.minecraft.commands.CommandSourceStack> context, String name) Retrieves the raw list of player names parsed by this argument.This method returns the names exactly as typed in the command input, without resolving them into
ServerPlayerinstances.In most cases, you should prefer using
getPlayerList(CommandContext, String)instead, unless you explicitly need the raw string values.- Parameters:
context- the command contextname- the name of the argument- Returns:
- a list of player names as strings
-
parse
-
listSuggestions
public <S> CompletableFuture<com.mojang.brigadier.suggestion.Suggestions> listSuggestions(com.mojang.brigadier.context.CommandContext<S> context, com.mojang.brigadier.suggestion.SuggestionsBuilder builder)
-