Fix entity used for respawn.
Using client entity for change location of ingame player - wrong.
You must use character for this.
@@ -212,17 +212,20 @@ public void onDisconnect(DisconnectedEvent event, EntityRef entity) {
@ReceiveEvent(priority = EventPriority.PRIORITY_CRITICAL, components = {ClientComponent.class})
public void setSpawnLocationOnRespawnRequest(RespawnRequestEvent event, EntityRef entity) {
- EntityRef clientInfo = entity.getComponent(ClientComponent.class).clientInfo;
+ ClientComponent clientComponent = entity.getComponent(ClientComponent.class);
+ EntityRef character = clientComponent.character;
+ EntityRef clientInfo = clientComponent.clientInfo;
+
Vector3f spawnPosition;
if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
spawnPosition = clientInfo.getComponent(StaticSpawnLocationComponent.class).position;
} else {
spawnPosition = worldGenerator.getSpawnPosition(entity);
}
- LocationComponent loc = entity.getComponent(LocationComponent.class);
+ LocationComponent loc = character.getComponent(LocationComponent.class);
loc.setWorldPosition(spawnPosition);
loc.setLocalRotation(new Quat4f()); // reset rotation
- entity.saveComponent(loc);
+ character.saveComponent(loc);
}
@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL, components = {ClientComponent.class})
@@ -242,16 +245,13 @@ private void respawnPlayer(EntityRef clientEntity) {
ClientComponent client = clientEntity.getComponent(ClientComponent.class);
EntityRef playerCharacter = client.character;
- LocationComponent location = clientEntity.getComponent(LocationComponent.class);
+ LocationComponent location = playerCharacter.getComponent(LocationComponent.class);
PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
Vector3f spawnPosition = playerFactory.findSpawnPositionFromLocationComponent(location);
playerCharacter.addComponent(new AliveCharacterComponent());
playerCharacter.send(new CharacterTeleportEvent(spawnPosition));
- location.setWorldPosition(spawnPosition);
- clientEntity.saveComponent(location);
-
logger.debug("Re-spawing player at: {}", spawnPosition);
Client clientListener = networkSystem.getOwner(clientEntity);
