private void addPlayersToSaveTransaction( SaveTransactionBuilder saveTransactionBuilder, NetworkSystem networkSystem) { unloadedAndSavingPlayerMap.clear(); /** * New entries might be added concurrently. By using putAll + clear to transfer entries we might * loose new ones added in between putAll and clear. By iterating we can make sure that all * entities removed from unloadedAndUnsavedPlayerMap get added to unloadedAndSavingPlayerMap. */ Iterator<Map.Entry<String, EntityData.PlayerStore>> unsavedEntryIterator = unloadedAndUnsavedPlayerMap.entrySet().iterator(); while (unsavedEntryIterator.hasNext()) { Map.Entry<String, EntityData.PlayerStore> entry = unsavedEntryIterator.next(); unloadedAndSavingPlayerMap.put(entry.getKey(), entry.getValue()); unsavedEntryIterator.remove(); } for (Client client : networkSystem.getPlayers()) { // If there is a newer undisposed version of the player,we don't need to save the disposed // version: unloadedAndSavingPlayerMap.remove(client.getId()); EntityRef character = client.getEntity().getComponent(ClientComponent.class).character; saveTransactionBuilder.addLoadedPlayer(client.getId(), createPlayerStore(client, character)); } for (Map.Entry<String, EntityData.PlayerStore> entry : unloadedAndSavingPlayerMap.entrySet()) { saveTransactionBuilder.addUnloadedPlayer(entry.getKey(), entry.getValue()); } }
@Override public void deactivatePlayer(Client client) { EntityRef character = client.getEntity().getComponent(ClientComponent.class).character; PlayerStoreBuilder playerStoreBuilder = createPlayerStore(client, character); EntityData.PlayerStore playerStore = playerStoreBuilder.build(getEntityManager()); deactivateOrDestroyEntityRecursive(character); unloadedAndUnsavedPlayerMap.put(client.getId(), playerStore); }