Search in sources :

Example 1 with DisplayNameComponent

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 + "'");
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) CharacterTeleportEvent(org.terasology.logic.characters.CharacterTeleportEvent) Vector3f(org.terasology.math.geom.Vector3f) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 2 with DisplayNameComponent

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 + "'");
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) CharacterTeleportEvent(org.terasology.logic.characters.CharacterTeleportEvent) Vector3f(org.terasology.math.geom.Vector3f) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 3 with DisplayNameComponent

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);
    }
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) ColorComponent(org.terasology.network.ColorComponent) Color(org.terasology.rendering.nui.Color) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 4 with DisplayNameComponent

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;
    }
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) PlayerCharacterComponent(org.terasology.logic.players.PlayerCharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Prefab(org.terasology.entitySystem.prefab.Prefab)

Example 5 with DisplayNameComponent

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;
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) PlayerCharacterComponent(org.terasology.logic.players.PlayerCharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent)

Aggregations

DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)23 EntityRef (org.terasology.entitySystem.entity.EntityRef)17 ClientComponent (org.terasology.network.ClientComponent)13 Command (org.terasology.logic.console.commandSystem.annotations.Command)9 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)4 LocationComponent (org.terasology.logic.location.LocationComponent)4 Vector3f (org.terasology.math.geom.Vector3f)4 Component (org.terasology.entitySystem.Component)2 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)2 Prefab (org.terasology.entitySystem.prefab.Prefab)2 ItemComponent (org.terasology.logic.inventory.ItemComponent)2 PlayerCharacterComponent (org.terasology.logic.players.PlayerCharacterComponent)2 ColorComponent (org.terasology.network.ColorComponent)2 LightComponent (org.terasology.rendering.logic.LightComponent)2 HashSet (java.util.HashSet)1 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)1 MovementMode (org.terasology.logic.characters.MovementMode)1 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)1 Client (org.terasology.network.Client)1