Search in sources :

Example 6 with CharacterTeleportEvent

use of org.terasology.logic.characters.CharacterTeleportEvent 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 7 with CharacterTeleportEvent

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

Aggregations

CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 Vector3f (org.terasology.math.geom.Vector3f)7 ClientComponent (org.terasology.network.ClientComponent)7 Command (org.terasology.logic.console.commandSystem.annotations.Command)6 LocationComponent (org.terasology.logic.location.LocationComponent)6 EntityRef (org.terasology.entitySystem.entity.EntityRef)5 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)4 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)2 AliveCharacterComponent (org.terasology.logic.characters.AliveCharacterComponent)1 MovementMode (org.terasology.logic.characters.MovementMode)1 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)1 OnPlayerRespawnedEvent (org.terasology.logic.players.event.OnPlayerRespawnedEvent)1 Vector3i (org.terasology.math.geom.Vector3i)1 Client (org.terasology.network.Client)1