Search in sources :

Example 31 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef 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 32 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef 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 33 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef 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)

Example 34 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class FirstPersonClientSystem method linkHeldItemLocationForLocalPlayer.

/**
 * Changes held item entity.
 *
 * <p>Detaches old held item and removes it's components. Adds components to new held item and
 * attaches it to the mount point entity.</p>
 */
private void linkHeldItemLocationForLocalPlayer(EntityRef newItem) {
    if (!newItem.equals(currentHeldItem)) {
        EntityRef camera = localPlayer.getCameraEntity();
        FirstPersonHeldItemMountPointComponent mountPointComponent = camera.getComponent(FirstPersonHeldItemMountPointComponent.class);
        if (mountPointComponent != null) {
            // currentHeldItem is at this point the old item
            if (currentHeldItem != EntityRef.NULL) {
                currentHeldItem.destroy();
            }
            // use the hand if there is no new item
            EntityRef newHeldItem;
            if (newItem == EntityRef.NULL) {
                newHeldItem = getHandEntity();
            } else {
                newHeldItem = newItem;
            }
            // create client side held item entity
            currentHeldItem = entityManager.create();
            // add the visually relevant components
            for (Component component : newHeldItem.iterateComponents()) {
                if (component instanceof VisualComponent) {
                    currentHeldItem.addComponent(component);
                }
            }
            // ensure world location is set
            currentHeldItem.addComponent(new LocationComponent());
            currentHeldItem.addComponent(new ItemIsHeldComponent());
            FirstPersonHeldItemTransformComponent heldItemTransformComponent = currentHeldItem.getComponent(FirstPersonHeldItemTransformComponent.class);
            if (heldItemTransformComponent == null) {
                heldItemTransformComponent = new FirstPersonHeldItemTransformComponent();
                currentHeldItem.addComponent(heldItemTransformComponent);
            }
            Location.attachChild(mountPointComponent.mountPointEntity, currentHeldItem, heldItemTransformComponent.translate, new Quat4f(TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.y, TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.x, TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.z), heldItemTransformComponent.scale);
        }
    }
}
Also used : VisualComponent(org.terasology.rendering.logic.VisualComponent) VisualComponent(org.terasology.rendering.logic.VisualComponent) CharacterHeldItemComponent(org.terasology.logic.characters.CharacterHeldItemComponent) OnActivatedComponent(org.terasology.entitySystem.entity.lifecycleEvents.OnActivatedComponent) OnChangedComponent(org.terasology.entitySystem.entity.lifecycleEvents.OnChangedComponent) CharacterComponent(org.terasology.logic.characters.CharacterComponent) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) Component(org.terasology.entitySystem.Component) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) Quat4f(org.terasology.math.geom.Quat4f)

Example 35 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class FirstPersonClientSystem method onHeldItemActivated.

@ReceiveEvent
public void onHeldItemActivated(OnActivatedComponent event, EntityRef character, CharacterHeldItemComponent heldItemComponent, CharacterComponent characterComponents) {
    if (localPlayer.getCharacterEntity().equals(character)) {
        EntityRef newItem = heldItemComponent.selectedItem;
        linkHeldItemLocationForLocalPlayer(newItem);
    }
}
Also used : EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

EntityRef (org.terasology.entitySystem.entity.EntityRef)337 Test (org.junit.Test)106 ClientComponent (org.terasology.network.ClientComponent)49 LocationComponent (org.terasology.logic.location.LocationComponent)45 Vector3f (org.terasology.math.geom.Vector3f)44 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)36 Vector3i (org.terasology.math.geom.Vector3i)34 Command (org.terasology.logic.console.commandSystem.annotations.Command)28 StringComponent (org.terasology.entitySystem.stubs.StringComponent)26 NetworkComponent (org.terasology.network.NetworkComponent)21 EntityData (org.terasology.protobuf.EntityData)21 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)17 Block (org.terasology.world.block.Block)16 Component (org.terasology.entitySystem.Component)15 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)15 CharacterComponent (org.terasology.logic.characters.CharacterComponent)14 Quat4f (org.terasology.math.geom.Quat4f)14 BlockComponent (org.terasology.world.block.BlockComponent)13 Map (java.util.Map)11 LocalPlayer (org.terasology.logic.players.LocalPlayer)11