ListPlayersCommand .java

net.minecraft.server.commands.ListPlayersCommand (class): members: register. strings: "commands.list.nameAndId", "commands.list.players", "uuids", "list".

net.minecraft.server.commandsclass37 linesserver1.6 KB

API Surface (1)

void register(final CommandDispatcher<CommandSourceStack> dispatcher)

String literals (4)

"list"
"uuids"
"commands.list.nameAndId"
"commands.list.players"

Code Graph: Dependencies (7)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ListPlayersCommand.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.commands;
2
3
import com.mojang.brigadier.CommandDispatcher;
4
import java.util.List;
5
import java.util.function.Function;
6
import net.minecraft.commands.CommandSourceStack;
7
import net.minecraft.commands.Commands;
8
import net.minecraft.network.chat.Component;
9
import net.minecraft.network.chat.ComponentUtils;
10
import net.minecraft.server.level.ServerPlayer;
11
import net.minecraft.server.players.PlayerList;
12
import net.minecraft.world.entity.player.Player;
13
14
public class ListPlayersCommand {
15
	public static void register(final CommandDispatcher<CommandSourceStack> dispatcher) {
16
		dispatcher.register(
17
			Commands.literal("list").executes(c -> listPlayers(c.getSource())).then(Commands.literal("uuids").executes(c -> listPlayersWithUuids(c.getSource())))
18
		);
19
	}
20
21
	private static int listPlayers(final CommandSourceStack source) {
22
		return format(source, Player::getDisplayName);
23
	}
24
25
	private static int listPlayersWithUuids(final CommandSourceStack source) {
26
		return format(source, player -> Component.translatable("commands.list.nameAndId", player.getName(), Component.translationArg(player.getGameProfile().id())));
27
	}
28
29
	private static int format(final CommandSourceStack source, final Function<ServerPlayer, Component> formatter) {
30
		PlayerList playerList = source.getServer().getPlayerList();
31
		List<ServerPlayer> players = playerList.getPlayers();
32
		Component listComponent = ComponentUtils.formatList(players, formatter);
33
		source.sendSuccess(() -> Component.translatable("commands.list.players", players.size(), playerList.getMaxPlayers(), listComponent), false);
34
		return players.size();
35
	}
36
}
37

Decompiled Minecraft 26.3 source of ListPlayersCommand (net/minecraft/server/commands/ListPlayersCommand.java) with Mojang official mappings, stored verbatim on the site.