Search in sources :

Example 1 with ClientInfoComponent

use of org.terasology.network.ClientInfoComponent in project Terasology by MovingBlocks.

the class PlayerNameTagSystem method onDisplayNameChange.

@ReceiveEvent
public void onDisplayNameChange(OnChangedComponent event, EntityRef clientInfoEntity, DisplayNameComponent displayNameComponent) {
    ClientInfoComponent clientInfoComp = clientInfoEntity.getComponent(ClientInfoComponent.class);
    if (clientInfoComp == null) {
        // not a client info object
        return;
    }
    EntityRef clientEntity = clientInfoComp.client;
    if (!clientEntity.exists()) {
        // offline players aren't visible: nothing to do
        return;
    }
    ClientComponent clientComponent = clientEntity.getComponent(ClientComponent.class);
    if (clientComponent == null) {
        logger.warn("Can't update name tag as client entity lacks ClietnComponent");
        return;
    }
    EntityRef characterEntity = clientComponent.character;
    if (characterEntity == null || !characterEntity.exists()) {
        // player has no character, nothing to do
        return;
    }
    NameTagComponent nameTagComponent = characterEntity.getComponent(NameTagComponent.class);
    if (nameTagComponent == null) {
        // local players don't have a name tag
        return;
    }
    nameTagComponent.text = displayNameComponent.name;
    characterEntity.saveComponent(nameTagComponent);
}
Also used : ClientInfoComponent(org.terasology.network.ClientInfoComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 2 with ClientInfoComponent

use of org.terasology.network.ClientInfoComponent in project Terasology by MovingBlocks.

the class AbstractClient method createClientInfoEntity.

private EntityRef createClientInfoEntity(EntityManager entityManager) {
    EntityRef clientInfo;
    clientInfo = entityManager.create("engine:clientInfo");
    // mark clientInfo entities with a dedicated component
    ClientInfoComponent cic = new ClientInfoComponent();
    cic.playerId = getId();
    clientInfo.addComponent(cic);
    return clientInfo;
}
Also used : ClientInfoComponent(org.terasology.network.ClientInfoComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 3 with ClientInfoComponent

use of org.terasology.network.ClientInfoComponent in project Terasology by MovingBlocks.

the class AbstractClient method disconnect.

@Override
public void disconnect() {
    EntityRef clientInfoEntity = clientEntity.getComponent(ClientComponent.class).clientInfo;
    ClientInfoComponent clientInfoComp = clientInfoEntity.getComponent(ClientInfoComponent.class);
    clientInfoComp.client = EntityRef.NULL;
    clientInfoEntity.saveComponent(clientInfoComp);
    clientEntity.destroy();
}
Also used : ClientInfoComponent(org.terasology.network.ClientInfoComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent)

Example 4 with ClientInfoComponent

use of org.terasology.network.ClientInfoComponent in project Terasology by MovingBlocks.

the class AbstractClient method createEntity.

protected void createEntity(String preferredName, Color color, EntityManager entityManager) {
    // Create player entity
    clientEntity = entityManager.create("engine:client");
    // TODO: Send event for clientInfo creation, don't create here.
    EntityRef clientInfo = findClientEntityRef(entityManager);
    if (!clientInfo.exists()) {
        clientInfo = createClientInfoEntity(entityManager);
    }
    ClientInfoComponent clientInfoComp = clientInfo.getComponent(ClientInfoComponent.class);
    clientInfoComp.client = clientEntity;
    clientInfo.saveComponent(clientInfoComp);
    ClientComponent clientComponent = clientEntity.getComponent(ClientComponent.class);
    clientComponent.clientInfo = clientInfo;
    clientEntity.saveComponent(clientComponent);
    addOrSetColorComponent(clientInfo, color);
    DisplayNameComponent displayNameComponent = clientInfo.getComponent(DisplayNameComponent.class);
    if (displayNameComponent == null || !displayNameComponent.name.equals(preferredName)) {
        String bestAvailableName = findUniquePlayerName(preferredName, entityManager, clientInfo);
        addOrSetDisplayNameComponent(clientInfo, bestAvailableName);
    }
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) ClientInfoComponent(org.terasology.network.ClientInfoComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent)

Aggregations

EntityRef (org.terasology.entitySystem.entity.EntityRef)4 ClientInfoComponent (org.terasology.network.ClientInfoComponent)4 ClientComponent (org.terasology.network.ClientComponent)3 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)1