Search in sources :

Example 61 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class MovementDebugCommands method teleportAllPlayersToPlayer.

@Command(shortDescription = "Teleport all users to specified user", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String teleportAllPlayersToPlayer(@CommandParam("username") String username) {
    Vector3f vPlayerLocation = Vector3f.zero();
    boolean bPlayerLocationWasFound = false;
    EntityRef playerEntity = null;
    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) {
                vPlayerLocation = locationComponent.getWorldPosition();
                bPlayerLocationWasFound = true;
                playerEntity = clientEntity;
            }
            break;
        }
    }
    if (!bPlayerLocationWasFound) {
        throw new IllegalArgumentException("No such user '" + username + "'");
    }
    MovementMode playerMovementMode = MovementMode.NONE;
    ClientComponent clientInfo = playerEntity.getComponent(ClientComponent.class);
    if (clientInfo != null) {
        CharacterMovementComponent playerMovementComponent = clientInfo.character.getComponent(CharacterMovementComponent.class);
        if (playerMovementComponent != null) {
            playerMovementMode = playerMovementComponent.mode;
        }
    }
    for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
        ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
        if (clientComp != null) {
            clientComp.character.send(new CharacterTeleportEvent(vPlayerLocation));
            CharacterMovementComponent characterMovementComponent = clientComp.character.getComponent(CharacterMovementComponent.class);
            if (characterMovementComponent != null && playerMovementMode != MovementMode.NONE && playerMovementMode != characterMovementComponent.mode) {
                clientComp.character.send(new SetMovementModeEvent(playerMovementMode));
            }
        }
    }
    return "All possible players teleported to " + username + " and set to " + playerMovementMode;
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) SetMovementModeEvent(org.terasology.logic.characters.events.SetMovementModeEvent) CharacterTeleportEvent(org.terasology.logic.characters.CharacterTeleportEvent) MovementMode(org.terasology.logic.characters.MovementMode) Vector3f(org.terasology.math.geom.Vector3f) CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) 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 62 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command 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 63 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command 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 64 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class MovementDebugCommands method playerEyeHeight.

@Command(shortDescription = "Sets the eye-height of the player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String playerEyeHeight(@Sender EntityRef client, @CommandParam("eye-height") float amount) {
    EntityRef player = client.getComponent(ClientComponent.class).character;
    try {
        GazeMountPointComponent gazeMountPointComponent = player.getComponent(GazeMountPointComponent.class);
        if (gazeMountPointComponent != null) {
            float prevHeight = gazeMountPointComponent.translate.y;
            gazeMountPointComponent.translate.y = amount;
            Location.removeChild(player, gazeMountPointComponent.gazeEntity);
            Location.attachChild(player, gazeMountPointComponent.gazeEntity, gazeMountPointComponent.translate, new Quat4f(Quat4f.IDENTITY));
            player.saveComponent(gazeMountPointComponent);
            return "Eye-height of player set to " + amount + " (was " + prevHeight + ")";
        }
        return "";
    } catch (NullPointerException e) {
        e.printStackTrace();
        return "";
    }
}
Also used : GazeMountPointComponent(org.terasology.logic.characters.GazeMountPointComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Quat4f(org.terasology.math.geom.Quat4f) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 65 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command 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)

Aggregations

Command (org.terasology.logic.console.commandSystem.annotations.Command)76 ClientComponent (org.terasology.network.ClientComponent)48 EntityRef (org.terasology.entitySystem.entity.EntityRef)28 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)16 Vector3f (org.terasology.math.geom.Vector3f)14 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)11 LocationComponent (org.terasology.logic.location.LocationComponent)10 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)9 ResourceUrn (org.terasology.assets.ResourceUrn)8 Prefab (org.terasology.entitySystem.prefab.Prefab)6 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)6 SimpleUri (org.terasology.engine.SimpleUri)5 BlockFamily (org.terasology.world.block.family.BlockFamily)4 Map (java.util.Map)3 AnatomyComponent (org.terasology.anatomy.component.AnatomyComponent)3 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2