use of org.terasology.logic.characters.CharacterTeleportEvent in project Terasology by MovingBlocks.
the class MovementDebugCommands method teleportMeToPlayer.
@Command(shortDescription = "Teleport to player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String teleportMeToPlayer(@Sender EntityRef sender, @CommandParam("username") String username) {
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) {
Vector3f vLocation = locationComponent.getWorldPosition();
ClientComponent clientComp = sender.getComponent(ClientComponent.class);
if (clientComp != null) {
clientComp.character.send(new CharacterTeleportEvent(vLocation));
return "Teleporting you to " + username + " at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
}
}
}
}
throw new IllegalArgumentException("No such user '" + username + "'");
}
use of org.terasology.logic.characters.CharacterTeleportEvent in project Terasology by MovingBlocks.
the class MovementDebugCommands method playerHeight.
@Command(shortDescription = "Sets the height of the player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String playerHeight(@Sender EntityRef client, @CommandParam("height") float amount) {
try {
ClientComponent clientComp = client.getComponent(ClientComponent.class);
CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
if (move != null) {
float prevHeight = move.height;
move.height = amount;
clientComp.character.saveComponent(move);
LocationComponent loc = client.getComponent(LocationComponent.class);
Vector3f currentPosition = loc.getWorldPosition();
clientComp.character.send(new CharacterTeleportEvent(new Vector3f(currentPosition.getX(), currentPosition.getY() + (amount - prevHeight) / 2, currentPosition.getZ())));
physics.removeCharacterCollider(clientComp.character);
physics.getCharacterCollider(clientComp.character);
return "Height of player set to " + amount + " (was " + prevHeight + ")";
}
return "";
} catch (NullPointerException e) {
e.printStackTrace();
return "";
}
}
use of org.terasology.logic.characters.CharacterTeleportEvent in project Terasology by MovingBlocks.
the class MovementDebugCommands method teleportPlayerToMe.
@Command(shortDescription = "Teleport player to you", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String teleportPlayerToMe(@Sender EntityRef sender, @CommandParam("username") String username) {
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 = sender.getComponent(LocationComponent.class);
if (locationComponent != null) {
Vector3f vLocation = locationComponent.getWorldPosition();
ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
if (clientComp != null) {
clientComp.character.send(new CharacterTeleportEvent(vLocation));
return "Teleporting " + username + " to you at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
}
}
}
}
throw new IllegalArgumentException("No such user '" + username + "'");
}
use of org.terasology.logic.characters.CharacterTeleportEvent in project Terasology by MovingBlocks.
the class PlayerSystem method respawnPlayer.
private void respawnPlayer(EntityRef clientEntity) {
ClientComponent client = clientEntity.getComponent(ClientComponent.class);
EntityRef playerCharacter = client.character;
LocationComponent location = clientEntity.getComponent(LocationComponent.class);
PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
Vector3f spawnPosition = playerFactory.findSpawnPositionFromLocationComponent(location);
location.setWorldPosition(spawnPosition);
clientEntity.saveComponent(location);
playerCharacter.addComponent(new AliveCharacterComponent());
playerCharacter.send(new CharacterTeleportEvent(spawnPosition));
logger.debug("Re-spawing player at: {}", spawnPosition);
Client clientListener = networkSystem.getOwner(clientEntity);
Vector3i distance = clientListener.getViewDistance().getChunkDistance();
updateRelevanceEntity(clientEntity, distance);
playerCharacter.send(new OnPlayerRespawnedEvent());
}
use of org.terasology.logic.characters.CharacterTeleportEvent 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;
}
Aggregations