Search in sources :

Example 21 with DisplayNameComponent

use of org.terasology.engine.logic.common.DisplayNameComponent 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)

Aggregations

DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)21 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)18 ClientComponent (org.terasology.engine.network.ClientComponent)13 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)10 Vector3f (org.joml.Vector3f)4 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)4 LocationComponent (org.terasology.engine.logic.location.LocationComponent)4 ColorComponent (org.terasology.engine.network.ColorComponent)3 PlayerCharacterComponent (org.terasology.engine.logic.players.PlayerCharacterComponent)2 HashSet (java.util.HashSet)1 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)1 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)1 MovementMode (org.terasology.engine.logic.characters.MovementMode)1 SetMovementModeEvent (org.terasology.engine.logic.characters.events.SetMovementModeEvent)1 ChatMessageEvent (org.terasology.engine.logic.chat.ChatMessageEvent)1 Client (org.terasology.engine.network.Client)1 ClientInfoComponent (org.terasology.engine.network.ClientInfoComponent)1 NetworkComponent (org.terasology.engine.network.NetworkComponent)1 Color (org.terasology.nui.Color)1