package net.minecraft.server.gui;

import java.util.Vector;
import javax.swing.JList;
import net.minecraft.server.MinecraftServer;

public class PlayerListComponent extends JList<String> {
    private final MinecraftServer server;
    private int tickCount;

    public PlayerListComponent(MinecraftServer server) {
        this.server = server;
        server.addTickable(this::tick);
    }

    public void tick() {
        if (this.tickCount++ % 20 == 0) {
            Vector<String> list = new Vector<>();

            for (int i = 0; i < this.server.getPlayerList().getPlayers().size(); i++) {
                list.add(this.server.getPlayerList().getPlayers().get(i).getGameProfile().getName());
            }

            this.setListData(list);
        }
    }
}
