use of org.terasology.engine.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class AbstractClient method createEntity.
/**
* Creates an entity for the client connection, checking if name and color options can be used.
* @param preferredName Passes players preferred name to check availability, giving a best alternative if it is used already.
* @param color Creates or changes the player's color component to match argument
* @param entityManager
*/
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);
}
}
use of org.terasology.engine.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class AbstractClient method addOrSetDisplayNameComponent.
/**
* Used to change or add a display name to the client entity.
* @param clientInfo
* @param name Function will set the client entities name to this.
*/
private void addOrSetDisplayNameComponent(EntityRef clientInfo, String name) {
DisplayNameComponent component = clientInfo.getComponent(DisplayNameComponent.class);
if (component != null) {
component.name = name;
clientInfo.saveComponent(component);
} else {
component = new DisplayNameComponent();
component.name = name;
clientInfo.addComponent(component);
}
}
use of org.terasology.engine.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class OnlineUsernameSuggester method suggest.
@Override
public Set<String> suggest(EntityRef sender, Object... resolvedParameters) {
Iterable<EntityRef> clients = entityManager.getEntitiesWith(ClientComponent.class);
Set<String> clientNames = Sets.newHashSet();
for (EntityRef client : clients) {
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
clientNames.add(displayNameComponent.name);
}
return clientNames;
}
use of org.terasology.engine.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class ServerCommands method kickUser.
@Command(shortDescription = "Kick user by name", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String kickUser(@CommandParam("username") String username) {
for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
if (username.equalsIgnoreCase(name.name)) {
return kick(clientEntity);
}
}
throw new IllegalArgumentException("No such user '" + username + "'");
}
use of org.terasology.engine.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class ServerCommands method kick.
private String kick(EntityRef clientEntity) {
Client client = networkSystem.getOwner(clientEntity);
if (!client.isLocal()) {
EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
logger.info("Kicking user {}", name.name);
networkSystem.forceDisconnect(client);
return "User kick triggered for '" + name.name + "'";
}
return "Request declined";
}
Aggregations