Fixes bug of player entity being destroyed after death
import org.terasology.logic.characters.AliveCharacterComponent;
import org.terasology.logic.characters.CharacterComponent;
import org.terasology.logic.characters.CharacterTeleportEvent;
+import org.terasology.logic.health.BeforeDestroyEvent;
import org.terasology.logic.location.Location;
import org.terasology.logic.location.LocationComponent;
import org.terasology.logic.players.event.OnPlayerRespawnedEvent;
@RegisterSystem(RegisterMode.AUTHORITY)
public class PlayerSystem extends BaseComponentSystem implements UpdateSubscriberSystem {
+ private static final Logger logger = LoggerFactory.getLogger(PlayerSystem.class);
@In
private EntityManager entityManager;
-
@In
private WorldGenerator worldGenerator;
-
@In
private WorldProvider worldProvider;
-
@In
private ChunkProvider chunkProvider;
-
@In
private NetworkSystem networkSystem;
-
private List<SpawningClientInfo> clientsPreparingToSpawn = Lists.newArrayList();
private List<SpawningClientInfo> clientsPreparingToRespawn = Lists.newArrayList();
- private static final Logger logger = LoggerFactory.getLogger(PlayerSystem.class);
-
@Override
public void initialise() {
}
@@ -108,6 +103,21 @@ public void update(float delta) {
}
}
+ /**
+ * This saves a dead player entity, which is meant to be preserved, to not be destroyed even after the
+ * {@link AliveCharacterComponent} is stripped off.
+ *
+ * @param event
+ * @param entity
+ * @param playerCharacterComponent
+ */
+ @ReceiveEvent
+ public void beforeDestroyDeadPlayer(BeforeDestroyEvent event, EntityRef entity, PlayerCharacterComponent playerCharacterComponent) {
+ if (!entity.hasComponent(AliveCharacterComponent.class)) {
+ event.consume();
+ }
+ }
+
@ReceiveEvent(components = ClientComponent.class)
public void onConnect(ConnectedEvent connected, EntityRef entity) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
