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.");
}
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;
}
Aggregations