use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class MovementDebugCommands method teleportMeToPlayer.
@Command(shortDescription = "Teleport to player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String teleportMeToPlayer(@Sender EntityRef sender, @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)) {
LocationComponent locationComponent = clientEntity.getComponent(LocationComponent.class);
if (locationComponent != null) {
Vector3f vLocation = locationComponent.getWorldPosition();
ClientComponent clientComp = sender.getComponent(ClientComponent.class);
if (clientComp != null) {
clientComp.character.send(new CharacterTeleportEvent(vLocation));
return "Teleporting you to " + username + " at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
}
}
}
}
throw new IllegalArgumentException("No such user '" + username + "'");
}
use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class MovementDebugCommands method teleportPlayerToMe.
@Command(shortDescription = "Teleport player to you", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String teleportPlayerToMe(@Sender EntityRef sender, @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)) {
LocationComponent locationComponent = sender.getComponent(LocationComponent.class);
if (locationComponent != null) {
Vector3f vLocation = locationComponent.getWorldPosition();
ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
if (clientComp != null) {
clientComp.character.send(new CharacterTeleportEvent(vLocation));
return "Teleporting " + username + " to you at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
}
}
}
}
throw new IllegalArgumentException("No such user '" + username + "'");
}
use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class PlayerNameTagSystem method onCharacterActivation.
/**
* Listening for {@link org.terasology.logic.players.event.OnPlayerSpawnedEvent} does not work, as it is an
* authority event that does not get processed at clients. That is why we listen for the activation.
*/
@ReceiveEvent(components = CharacterComponent.class)
public void onCharacterActivation(OnActivatedComponent event, EntityRef characterEntity, CharacterComponent characterComponent) {
EntityRef ownerEntity = networkSystem.getOwnerEntity(characterEntity);
if (ownerEntity == null) {
// NPC
return;
}
ClientComponent clientComponent = ownerEntity.getComponent(ClientComponent.class);
if (clientComponent == null) {
logger.warn("Can't create player based name tag for character as owner has no client component");
return;
}
if (clientComponent.local) {
// the character belongs to the local player and does not need a name tag
return;
}
EntityRef clientInfoEntity = clientComponent.clientInfo;
DisplayNameComponent displayNameComponent = clientInfoEntity.getComponent(DisplayNameComponent.class);
if (displayNameComponent == null) {
logger.error("Can't create player based name tag for character as client info has no DisplayNameComponent");
return;
}
String name = displayNameComponent.name;
float yOffset = characterComponent.nameTagOffset;
Color color = Color.WHITE;
ColorComponent colorComponent = clientInfoEntity.getComponent(ColorComponent.class);
if (colorComponent != null) {
color = colorComponent.color;
}
NameTagComponent nameTagComponent = characterEntity.getComponent(NameTagComponent.class);
boolean newComponent = nameTagComponent == null;
if (nameTagComponent == null) {
nameTagComponent = new NameTagComponent();
}
nameTagComponent.text = name;
nameTagComponent.textColor = color;
nameTagComponent.yOffset = yOffset;
if (newComponent) {
characterEntity.addComponent(nameTagComponent);
} else {
characterEntity.saveComponent(nameTagComponent);
}
}
use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class CharacterSystem method getInstigatorName.
/**
* Extracts the name from an entity.
* If the entity is a character, then the display name from the {@link ClientComponent#clientInfo} is used.
* Otherwise the entity itself is checked for a {@link DisplayNameComponent}.
* In the last case, the prefab name of the entity is used, e.g. "engine:player" will be parsed to "Player".
* @param instigator The entity for which an instigator name is needed.
* @return The instigator name.
*/
public String getInstigatorName(EntityRef instigator) {
if (instigator.hasComponent(CharacterComponent.class)) {
EntityRef instigatorClient = instigator.getComponent(CharacterComponent.class).controller;
EntityRef instigatorClientInfo = instigatorClient.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent displayNameComponent = instigatorClientInfo.getComponent(DisplayNameComponent.class);
return displayNameComponent.name;
} else if (instigator.getParentPrefab() != null) {
// A DisplayName can be specified in the entity prefab
// Otherwise, the game will attempt to generate one from the name of that prefab
Prefab parentPrefab = instigator.getParentPrefab();
if (parentPrefab.hasComponent(DisplayNameComponent.class)) {
DisplayNameComponent displayNameComponent = parentPrefab.getComponent(DisplayNameComponent.class);
return displayNameComponent.name;
} else {
String instigatorName = parentPrefab.getName();
// getParentPrefab.getName() returns a ResourceUrn String such as "engine:player"
// The following calls change the damage type to be more readable
// For instance, "engine:player" becomes "Player"
instigatorName = instigatorName.replaceAll(".*:(.*)", "$1");
instigatorName = Character.toUpperCase(instigatorName.charAt(0)) + instigatorName.substring(1);
return instigatorName;
}
} else {
return null;
}
}
use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class CharacterSystem method getPlayerNameFromCharacter.
private String getPlayerNameFromCharacter(EntityRef character) {
CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
if (characterComponent == null) {
return "?";
}
EntityRef controller = characterComponent.controller;
ClientComponent clientComponent = controller.getComponent(ClientComponent.class);
EntityRef clientInfo = clientComponent.clientInfo;
DisplayNameComponent displayNameComponent = clientInfo.getComponent(DisplayNameComponent.class);
if (displayNameComponent == null) {
return "?";
}
return displayNameComponent.name;
}
Aggregations