Class PlayerListArgument

java.lang.Object
net.kamkeyke.raccooncore.command.argumenttype.PlayerListArgument
All Implemented Interfaces:
com.mojang.brigadier.arguments.ArgumentType<List<String>>

public class PlayerListArgument extends Object implements com.mojang.brigadier.arguments.ArgumentType<List<String>>
Custom argument type for commands that allows the selection of multiple player names in a formatted list enclosed in curly braces. Makes it easier to pass multiple players as arguments.

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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 of ServerPlayer instances.
    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.
    <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)
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.mojang.brigadier.arguments.ArgumentType

    getExamples
  • Constructor Details

    • PlayerListArgument

      public PlayerListArgument()
  • Method Details

    • players

      public static PlayerListArgument 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 of ServerPlayer instances.

      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 ServerPlayer objects.

      Only currently online players will be returned. Any names that cannot be resolved to an online player will be ignored.

      Parameters:
      context - the command context
      name - the name of the argument
      Returns:
      a collection of resolved ServerPlayer objects
    • 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 ServerPlayer instances.

      In most cases, you should prefer using getPlayerList(CommandContext, String) instead, unless you explicitly need the raw string values.

      Parameters:
      context - the command context
      name - the name of the argument
      Returns:
      a list of player names as strings
    • parse

      public List<String> parse(com.mojang.brigadier.StringReader stringReader) throws com.mojang.brigadier.exceptions.CommandSyntaxException
      Specified by:
      parse in interface com.mojang.brigadier.arguments.ArgumentType<List<String>>
      Throws:
      com.mojang.brigadier.exceptions.CommandSyntaxException
    • listSuggestions

      public <S> CompletableFuture<com.mojang.brigadier.suggestion.Suggestions> listSuggestions(com.mojang.brigadier.context.CommandContext<S> context, com.mojang.brigadier.suggestion.SuggestionsBuilder builder)
      Specified by:
      listSuggestions in interface com.mojang.brigadier.arguments.ArgumentType<List<String>>