Search in sources :

Example 1 with AfkComponent

use of org.terasology.engine.logic.afk.AfkComponent in project Terasology by MovingBlocks.

the class OnlinePlayersOverlay method determinePlayerAndPing.

private String determinePlayerAndPing(PingStockComponent pingStockComponent) {
    Map<EntityRef, Long> pingMap = pingStockComponent.getValues();
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (Map.Entry<EntityRef, Long> entry : pingMap.entrySet()) {
        EntityRef clientEntity = entry.getKey();
        if (clientEntity == null || clientEntity.getComponent(ClientComponent.class) == null) {
            logger.warn("OnlinePlayersOverlay skipping a null client entity or component");
            continue;
        }
        if (!first) {
            sb.append("\n");
        }
        ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
        AfkComponent afkComponent = clientEntity.getComponent(AfkComponent.class);
        if (afkComponent != null) {
            if (afkComponent.afk) {
                sb.append(FontColor.getColored("[AFK]", Color.red));
                sb.append(" ");
            }
        }
        sb.append(PlayerUtil.getColoredPlayerName(clientComp.clientInfo));
        sb.append(" ");
        Long pingValue = pingMap.get(clientEntity);
        if (pingValue == null) {
            sb.append("-");
        } else {
            sb.append(pingValue.toString());
            sb.append("ms");
        }
        first = false;
    }
    return sb.toString();
}
Also used : AfkComponent(org.terasology.engine.logic.afk.AfkComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Map(java.util.Map) ClientComponent(org.terasology.engine.network.ClientComponent)

Aggregations

Map (java.util.Map)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 AfkComponent (org.terasology.engine.logic.afk.AfkComponent)1 ClientComponent (org.terasology.engine.network.ClientComponent)1