package net.minecraft.server.commands;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.context.CommandContext;
import java.util.List;
import net.minecraft.server.players.PlayerList;
import net.minecraft.network.chat.TranslatableComponent;
import java.util.Collection;
import net.minecraft.network.chat.ComponentUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import java.util.function.Function;
import net.minecraft.world.entity.player.Player;
import net.minecraft.commands.Commands;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import com.mojang.brigadier.CommandDispatcher;

public class ListPlayersCommand {
    public static void register(final CommandDispatcher<CommandSourceStack> commandDispatcher) {
        commandDispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("list").executes(commandContext -> listPlayers((CommandSourceStack)commandContext.getSource()))).then(Commands.literal("uuids").executes(commandContext -> listPlayersWithUuids((CommandSourceStack)commandContext.getSource()))));
    }
    
    private static int listPlayers(final CommandSourceStack cq) {
        return format(cq, Player::getDisplayName);
    }
    
    private static int listPlayersWithUuids(final CommandSourceStack cq) {
        return format(cq, Player::getDisplayNameWithUuid);
    }
    
    private static int format(final CommandSourceStack cq, final Function<ServerPlayer, Component> function) {
        final PlayerList zo3 = cq.getServer().getPlayerList();
        final List<ServerPlayer> list4 = zo3.getPlayers();
        final Component lf5 = ComponentUtils.<ServerPlayer>formatList(list4, function);
        cq.sendSuccess(new TranslatableComponent("commands.list.players", new Object[] { list4.size(), zo3.getMaxPlayers(), lf5 }), false);
        return list4.size();
    }
}
