Source:
<code>public CompletableFuture<Void> joinGame(Game game, String password) { if (isRunning()) { log.debug("Game is running, ignoring join request"); notificationService.addImmediateErrorNotification(new UnsupportedOperationException("Forged Alliances is already running"), "game.gameRunning"); return completedFuture(null); } if (!preferencesService.isGamePathValid()) { CompletableFuture<Path> gameDirectoryFuture = postGameDirectoryChooseEvent(); return gameDirectoryFuture.thenCompose(path -> joinGame(game, password)); } <START> if (inMatchmakerQueue.get()) { notificationService.addNotification(new ImmediateNotification( i18n.get("teammatchmaking.notification.customAlreadyInQueue.title"), i18n.get("teammatchmaking.notification.customAlreadyInQueue.message"), Severity.WARN, Collections.singletonList(new Action(i18n.get("dismiss"))) <END> )); return completedFuture(null); } log.info("Joining game: '{}' ({})", game.getTitle(), game.getId()); Map<String, Integer> featuredModVersions = game.getFeaturedModVersions(); Set<String> simModUIds = game.getSimMods().keySet(); return modService.getFeaturedMod(game.getFeaturedMod()) .thenCompose(featuredModBean -> updateGameIfNecessary(featuredModBean, null, featuredModVersions, simModUIds)) .thenAccept(aVoid -> { try { modService.enableSimMods(simModUIds); } catch (IOException e) { log.warn("SimMods could not be enabled", e); } }) .thenCompose(aVoid -> downloadMapIfNecessary(game.getMapFolderName())) .thenCompose(aVoid -> fafService.requestJoinGame(game.getId(), password)) .thenAccept(gameLaunchMessage -> { synchronized (currentGame) { game.setPassword(password); currentGame.set(game); } startGame(gameLaunchMessage, null, RatingMode.GLOBAL); }) .exceptionally(throwable -> { log.warn("Game could not be joined", throwable); notificationService.addImmediateErrorNotification(throwable, "games.couldNotJoin"); return null; }); }</code><technical_language>duplicate code, please put dedicated method</technical_language>

Target:
public CompletableFuture<Void> joinGame(Game game, String password) { if (isRunning()) { log.debug("Game is running, ignoring join request"); notificationService.addImmediateErrorNotification(new UnsupportedOperationException("Forged Alliances is already running"), "game.gameRunning"); return completedFuture(null); } if (!preferencesService.isGamePathValid()) { CompletableFuture<Path> gameDirectoryFuture = postGameDirectoryChooseEvent(); return gameDirectoryFuture.thenCompose(path -> joinGame(game, password)); } if (inMatchmakerQueue.get()) { addAlreadyInQueueNotification(); return completedFuture(null); } log.info("Joining game: '{}' ({})", game.getTitle(), game.getId()); Map<String, Integer> featuredModVersions = game.getFeaturedModVersions(); Set<String> simModUIds = game.getSimMods().keySet(); return modService.getFeaturedMod(game.getFeaturedMod()) .thenCompose(featuredModBean -> updateGameIfNecessary(featuredModBean, null, featuredModVersions, simModUIds)) .thenAccept(aVoid -> { try { modService.enableSimMods(simModUIds); } catch (IOException e) { log.warn("SimMods could not be enabled", e); } }) .thenCompose(aVoid -> downloadMapIfNecessary(game.getMapFolderName())) .thenCompose(aVoid -> fafService.requestJoinGame(game.getId(), password)) .thenAccept(gameLaunchMessage -> { synchronized (currentGame) { game.setPassword(password); currentGame.set(game); } startGame(gameLaunchMessage, null, RatingMode.GLOBAL); }) .exceptionally(throwable -> { log.warn("Game could not be joined", throwable); notificationService.addImmediateErrorNotification(throwable, "games.couldNotJoin"); return null; }); }