try {
EntityManager entityManager = PersistenceManager.getInstance().getEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();
GameJournal gameJournalEntry = new GameJournal();
String mapname = IConstants.Map.getMapById(mapId).getFilename();
mapname = mapname.replaceAll("de/creepsmash/client/resources/maps/map_", "");
gameJournalEntry.setMap(mapname.replaceAll(".map", ""));
gameJournalEntry.setName(gameName);
gameJournalEntry.setNumPlayers(playerNamePositionMap.size());
gameJournalEntry.setStart_date(startDate);
gameJournalEntry.setEnd_date(System.currentTimeMillis() / 1000);
int i = 0;
for (String playerName : playerNamePositionMap.keySet()) {
i++;
Player player = AuthenticationService.getPlayer(playerName);
if (player != null) {
int num = playerNamePositionMap.get(playerName);
// Ich habe keine idee wie man da ohne switch macht^^
switch(i) {
case 1:
gameJournalEntry.setPlayer1(player.getName());
gameJournalEntry.setPlayer1_score(player.getOldElopoints());
gameJournalEntry.setScore1(player.getElopoints());
gameJournalEntry.setPlayer1_position(num);
gameJournalEntry.setIp1(player.getIp());
gameJournalEntry.setMac1(player.getMac());
break;
case 2:
gameJournalEntry.setPlayer2(player.getName());
gameJournalEntry.setPlayer2_score(player.getOldElopoints());
gameJournalEntry.setScore2(player.getElopoints());
gameJournalEntry.setPlayer2_position(num);
gameJournalEntry.setIp2(player.getIp());
gameJournalEntry.setMac2(player.getMac());
break;
case 3:
gameJournalEntry.setPlayer3(player.getName());
gameJournalEntry.setPlayer3_score(player.getOldElopoints());
gameJournalEntry.setScore3(player.getElopoints());
gameJournalEntry.setPlayer3_position(num);
gameJournalEntry.setIp3(player.getIp());
gameJournalEntry.setMac3(player.getMac());
break;
case 4:
gameJournalEntry.setPlayer4(player.getName());
gameJournalEntry.setPlayer4_score(player.getOldElopoints());
gameJournalEntry.setScore4(player.getElopoints());
gameJournalEntry.setPlayer4_position(num);
gameJournalEntry.setIp4(player.getIp());
gameJournalEntry.setMac4(player.getMac());
break;
default:
logger.error("False number of players: " + i);
break;
}