Search in sources :

Example 1 with SetMovementModeEvent

use of org.terasology.logic.characters.events.SetMovementModeEvent in project Terasology by MovingBlocks.

the class MovementDebugCommands method ghost.

@Command(shortDescription = "Grants flight and movement through walls", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String ghost(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    clientComp.character.send(new SetMovementModeEvent(MovementMode.GHOSTING));
    return "Ghost mode toggled";
}
Also used : SetMovementModeEvent(org.terasology.logic.characters.events.SetMovementModeEvent) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 2 with SetMovementModeEvent

use of org.terasology.logic.characters.events.SetMovementModeEvent in project Terasology by MovingBlocks.

the class MovementDebugCommands method flight.

@Command(shortDescription = "Grants flight", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String flight(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    clientComp.character.send(new SetMovementModeEvent(MovementMode.FLYING));
    return "Flight mode toggled";
}
Also used : SetMovementModeEvent(org.terasology.logic.characters.events.SetMovementModeEvent) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 3 with SetMovementModeEvent

use of org.terasology.logic.characters.events.SetMovementModeEvent 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)

Aggregations

SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)3 Command (org.terasology.logic.console.commandSystem.annotations.Command)3 ClientComponent (org.terasology.network.ClientComponent)3 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)1 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)1 MovementMode (org.terasology.logic.characters.MovementMode)1 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)1 LocationComponent (org.terasology.logic.location.LocationComponent)1 Vector3f (org.terasology.math.geom.Vector3f)1