Search in sources :

Example 1 with ClientComponent

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

the class OnlinePlayersOverlay method determinePlayerAndPing.

private String determinePlayerAndPing(PingStockComponent pingStockComponent) {
    Iterable<EntityRef> allClients = entityManager.getEntitiesWith(ClientComponent.class);
    Map<EntityRef, Long> pingMap = pingStockComponent.getValues();
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (EntityRef clientEntity : allClients) {
        if (!first) {
            sb.append("\n");
        }
        ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
        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 : EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent)

Example 2 with ClientComponent

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

use of org.terasology.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.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 4 with ClientComponent

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

the class MovementDebugCommands method playerHeight.

@Command(shortDescription = "Sets the height of the player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String playerHeight(@Sender EntityRef client, @CommandParam("height") float amount) {
    try {
        ClientComponent clientComp = client.getComponent(ClientComponent.class);
        CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
        if (move != null) {
            float prevHeight = move.height;
            move.height = amount;
            clientComp.character.saveComponent(move);
            LocationComponent loc = client.getComponent(LocationComponent.class);
            Vector3f currentPosition = loc.getWorldPosition();
            clientComp.character.send(new CharacterTeleportEvent(new Vector3f(currentPosition.getX(), currentPosition.getY() + (amount - prevHeight) / 2, currentPosition.getZ())));
            physics.removeCharacterCollider(clientComp.character);
            physics.getCharacterCollider(clientComp.character);
            return "Height of player set to " + amount + " (was " + prevHeight + ")";
        }
        return "";
    } catch (NullPointerException e) {
        e.printStackTrace();
        return "";
    }
}
Also used : CharacterTeleportEvent(org.terasology.logic.characters.CharacterTeleportEvent) Vector3f(org.terasology.math.geom.Vector3f) CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 5 with ClientComponent

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

the class MovementDebugCommands method setJumpSpeed.

@Command(shortDescription = "Set jump speed", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setJumpSpeed(@Sender EntityRef client, @CommandParam("amount") float amount) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    if (move != null) {
        float oldSpeed = move.jumpSpeed;
        move.jumpSpeed = amount;
        clientComp.character.saveComponent(move);
        return "Jump speed set to " + amount + " (was " + oldSpeed + ")";
    }
    return "";
}
Also used : CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.network.ClientComponent) 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