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 cz) {
        return format(cz, Player::getDisplayName);
    }
    
    private static int listPlayersWithUuids(final CommandSourceStack cz) {
        return format(cz, Player::getDisplayNameWithUuid);
    }
    
    private static int format(final CommandSourceStack cz, final Function<ServerPlayer, Component> function) {
        final PlayerList abp3 = cz.getServer().getPlayerList();
        final List<ServerPlayer> list4 = abp3.getPlayers();
        final Component mr5 = ComponentUtils.<ServerPlayer>formatList(list4, function);
        cz.sendSuccess(new TranslatableComponent("commands.list.players", new Object[] { list4.size(), abp3.getMaxPlayers(), mr5 }), false);
        return list4.size();
    }
}
