Search in sources :

Example 11 with ClientComponent

use of org.terasology.network.ClientComponent 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 12 with ClientComponent

use of org.terasology.network.ClientComponent 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 13 with ClientComponent

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

the class PermissionCommands method givePermission.

@Command(shortDescription = "Gives specified permission to player", helpText = "Gives specified permission to player", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String givePermission(@CommandParam(value = "player", suggester = UsernameSuggester.class) String player, @CommandParam("permission") String permission, @Sender EntityRef requester) {
    boolean permissionGiven = false;
    ClientComponent requesterClientComponent = requester.getComponent(ClientComponent.class);
    EntityRef requesterClientInfo = requesterClientComponent.clientInfo;
    if (!permissionManager.hasPermission(requesterClientInfo, permission)) {
        return String.format("You can't give the permission %s because you don't have it yourself", permission);
    }
    for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        if (clientHasName(clientComponent, player)) {
            permissionManager.addPermission(clientComponent.clientInfo, permission);
            permissionGiven = true;
        }
    }
    if (permissionGiven) {
        return "Permission " + permission + " added to player " + player;
    } else {
        return "Unable to find player " + player;
    }
}
Also used : ClientComponent(org.terasology.network.ClientComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 14 with ClientComponent

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

the class PermissionCommands method usePermissionKey.

@Command(shortDescription = "Use an one time key to get all permissions", helpText = "The config file contains a one time key which can be used to get all permissions.", runOnServer = true, requiredPermission = PermissionManager.NO_PERMISSION)
public String usePermissionKey(@CommandParam("key") String key, @Sender EntityRef client) {
    PermissionConfig permissionConfig = config.getPermission();
    String expectedKey = permissionConfig.getOneTimeAuthorizationKey();
    if (expectedKey != null && !expectedKey.equals("") && key.equals(expectedKey)) {
        permissionConfig.setOneTimeAuthorizationKey("");
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        EntityRef clientInfo = clientComponent.clientInfo;
        for (String permission : findAllPermissions()) {
            permissionManager.addPermission(clientInfo, permission);
        }
        PermissionSetComponent permissionSetComp = clientInfo.getComponent(PermissionSetComponent.class);
        return "Permission key used: You have now the following permissions: " + permissionSetComp.permissions;
    } else {
        return "Key invalid or used";
    }
}
Also used : PermissionConfig(org.terasology.config.PermissionConfig) ClientComponent(org.terasology.network.ClientComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 15 with ClientComponent

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

the class CameraClientSystem method mountCamera.

private void mountCamera() {
    ClientComponent clientComponent = localPlayer.getClientEntity().getComponent(ClientComponent.class);
    EntityRef targetEntityForCamera = GazeAuthoritySystem.getGazeEntityForCharacter(clientComponent.character);
    LocationComponent cameraLocation = clientComponent.camera.getComponent(LocationComponent.class);
    // if the camera already has a location,  use that as the relative position of the camera
    if (cameraLocation != null) {
        Location.attachChild(targetEntityForCamera, clientComponent.camera, cameraLocation.getLocalPosition(), new Quat4f(Quat4f.IDENTITY));
    } else {
        Location.attachChild(targetEntityForCamera, clientComponent.camera, Vector3f.zero(), new Quat4f(Quat4f.IDENTITY));
    }
}
Also used : ClientComponent(org.terasology.network.ClientComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) Quat4f(org.terasology.math.geom.Quat4f)

Aggregations

ClientComponent (org.terasology.network.ClientComponent)64 Command (org.terasology.logic.console.commandSystem.annotations.Command)37 EntityRef (org.terasology.entitySystem.entity.EntityRef)28 LocationComponent (org.terasology.logic.location.LocationComponent)13 Vector3f (org.terasology.math.geom.Vector3f)13 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)10 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)8 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)5 Prefab (org.terasology.entitySystem.prefab.Prefab)5 LocalPlayer (org.terasology.logic.players.LocalPlayer)4 Quat4f (org.terasology.math.geom.Quat4f)4 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)3 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 Client (org.terasology.network.Client)3 ResourceUrn (org.terasology.assets.ResourceUrn)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)2