Search in sources :

Example 51 with ClientComponent

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

the class MovementDebugCommands method restoreSpeed.

@Command(shortDescription = "Restore normal speed values", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String restoreSpeed(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    Optional<Prefab> prefab = Assets.get(new ResourceUrn("engine:player"), Prefab.class);
    CharacterMovementComponent moveDefault = prefab.get().getComponent(CharacterMovementComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    if (move != null && moveDefault != null) {
        move.jumpSpeed = moveDefault.jumpSpeed;
        move.speedMultiplier = moveDefault.speedMultiplier;
        move.runFactor = moveDefault.runFactor;
        move.stepHeight = moveDefault.stepHeight;
        move.slopeFactor = moveDefault.slopeFactor;
        move.distanceBetweenFootsteps = moveDefault.distanceBetweenFootsteps;
        clientComp.character.saveComponent(move);
    }
    return "Normal speed values restored";
}
Also used : CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ResourceUrn(org.terasology.assets.ResourceUrn) ClientComponent(org.terasology.network.ClientComponent) Prefab(org.terasology.entitySystem.prefab.Prefab) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 52 with ClientComponent

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

the class MovementDebugCommands method showHeight.

@Command(shortDescription = "Show your Height", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String showHeight(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    float height = move.height;
    GazeMountPointComponent gazeMountPointComponent = clientComp.character.getComponent(GazeMountPointComponent.class);
    float eyeHeight = gazeMountPointComponent.translate.y;
    return "Your height: " + height + " Eye-height: " + eyeHeight;
}
Also used : GazeMountPointComponent(org.terasology.logic.characters.GazeMountPointComponent) CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 53 with ClientComponent

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

the class MovementDebugCommands method teleportPlayerToPlayer.

@Command(shortDescription = "Teleport User1 to User2", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String teleportPlayerToPlayer(@CommandParam("usernameFrom") String usernameFrom, @CommandParam("usernameTo") String usernameTo) {
    if (usernameFrom.equalsIgnoreCase(usernameTo)) {
        throw new IllegalArgumentException("Why teleport to yourself...");
    }
    EntityRef entityFrom = null;
    EntityRef entityTo = null;
    boolean foundEntityFrom = false;
    boolean foundEntityTo = false;
    for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
        EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
        DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
        if (!foundEntityFrom && usernameFrom.equalsIgnoreCase(name.name)) {
            entityFrom = clientEntity;
            foundEntityFrom = true;
        } else if (!foundEntityTo && usernameTo.equalsIgnoreCase(name.name)) {
            entityTo = clientEntity;
            foundEntityTo = true;
        }
        if (foundEntityFrom && foundEntityTo) {
            break;
        }
    }
    if (!foundEntityFrom) {
        throw new IllegalArgumentException("No such user '" + usernameFrom + "'");
    }
    if (!foundEntityTo) {
        throw new IllegalArgumentException("No such user '" + usernameTo + "'");
    }
    LocationComponent locationComponent = entityTo.getComponent(LocationComponent.class);
    if (locationComponent != null) {
        Vector3f vLocation = locationComponent.getWorldPosition();
        ClientComponent clientComp = entityFrom.getComponent(ClientComponent.class);
        if (clientComp != null) {
            clientComp.character.send(new CharacterTeleportEvent(vLocation));
            return "Teleporting " + usernameFrom + " to " + usernameTo + " at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
        }
    }
    throw new IllegalArgumentException("User " + usernameTo + " has an invalid location.");
}
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 54 with ClientComponent

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

the class MovementDebugCommands method teleportCommand.

@Command(value = "teleport", shortDescription = "Teleports you to a location", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String teleportCommand(@Sender EntityRef sender, @CommandParam("x") float x, @CommandParam("y") float y, @CommandParam("z") float z) {
    ClientComponent clientComp = sender.getComponent(ClientComponent.class);
    clientComp.character.send(new CharacterTeleportEvent(new Vector3f(x, y, z)));
    return "Teleporting  to " + x + " " + y + " " + z;
}
Also used : CharacterTeleportEvent(org.terasology.logic.characters.CharacterTeleportEvent) Vector3f(org.terasology.math.geom.Vector3f) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 55 with ClientComponent

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

the class PermissionCommands method removePermission.

@Command(shortDescription = "Removes specified permission from player", helpText = "Removes specified permission from player", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String removePermission(@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 remove 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.removePermission(clientComponent.clientInfo, permission);
            permissionGiven = true;
        }
    }
    if (permissionGiven) {
        return "Permission " + permission + " removed from 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)

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