Search in sources :

Example 51 with ClientComponent

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

the class MovementDebugCommands method stepHeight.

@Command(shortDescription = "Sets the height the player can step up", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String stepHeight(@Sender EntityRef client, @CommandParam("height") float amount) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    if (move != null) {
        float prevStepHeight = move.stepHeight;
        move.stepHeight = amount;
        clientComp.character.saveComponent(move);
        return "Ground friction set to " + amount + " (was " + prevStepHeight + ")";
    }
    return "";
}
Also used : CharacterMovementComponent(org.terasology.engine.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.engine.network.ClientComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 52 with ClientComponent

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

the class MovementDebugCommands method setSpeedMultiplier.

@Command(shortDescription = "Set speed multiplier", helpText = "Set speedMultiplier", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setSpeedMultiplier(@Sender EntityRef client, @CommandParam("amount") float amount) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    if (move != null) {
        float oldSpeedMultipler = move.speedMultiplier;
        move.speedMultiplier = amount;
        clientComp.character.saveComponent(move);
        return "Speed multiplier set to " + amount + " (was " + oldSpeedMultipler + ")";
    }
    return "";
}
Also used : CharacterMovementComponent(org.terasology.engine.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.engine.network.ClientComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 53 with ClientComponent

use of org.terasology.engine.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(new Vector3f());
        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.engine.logic.common.DisplayNameComponent) CharacterTeleportEvent(org.terasology.engine.logic.characters.CharacterTeleportEvent) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 54 with ClientComponent

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

the class OnlinePlayersOverlay method determinePlayerAndPing.

private String determinePlayerAndPing(PingStockComponent pingStockComponent) {
    Map<EntityRef, Long> pingMap = pingStockComponent.getValues();
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (Map.Entry<EntityRef, Long> entry : pingMap.entrySet()) {
        EntityRef clientEntity = entry.getKey();
        if (clientEntity == null || clientEntity.getComponent(ClientComponent.class) == null) {
            logger.warn("OnlinePlayersOverlay skipping a null client entity or component");
            continue;
        }
        if (!first) {
            sb.append("\n");
        }
        ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
        AfkComponent afkComponent = clientEntity.getComponent(AfkComponent.class);
        if (afkComponent != null) {
            if (afkComponent.afk) {
                sb.append(FontColor.getColored("[AFK]", Color.red));
                sb.append(" ");
            }
        }
        sb.append(PlayerUtil.getColoredPlayerName(clientComp.clientInfo));
        sb.append(" ");
        Long pingValue = pingMap.get(clientEntity);
        if (pingValue == null) {
            sb.append("-");
        } else {
            sb.append(pingValue.toString());
            sb.append("ms");
        }
        first = false;
    }
    return sb.toString();
}
Also used : AfkComponent(org.terasology.engine.logic.afk.AfkComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Map(java.util.Map) ClientComponent(org.terasology.engine.network.ClientComponent)

Aggregations

ClientComponent (org.terasology.engine.network.ClientComponent)54 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)30 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)27 Vector3f (org.joml.Vector3f)13 LocationComponent (org.terasology.engine.logic.location.LocationComponent)13 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)10 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)8 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)6 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)6 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)4 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)4 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)4 Quaternionf (org.joml.Quaternionf)3 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)3 LocalPlayer (org.terasology.engine.logic.players.LocalPlayer)3 Client (org.terasology.engine.network.Client)3 Vector3ic (org.joml.Vector3ic)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 AliveCharacterComponent (org.terasology.engine.logic.characters.AliveCharacterComponent)2