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);
}
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;
}
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();
}
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);
}
}
Aggregations