refactor: extracted method in LobbyManager

This commit is contained in:
Yannik Bretschneider 2021-06-06 21:35:48 +02:00
parent 3ab8d57829
commit e029106a11

View File

@ -60,7 +60,7 @@ public class LobbyManager {
targetedLobby = initializeNewLobby(resourceDescriptor);
} else {
Logger.info("No free lobby spot available, sending error and disconnecting Client");
// TODO: Implement this!
}
} else if (targetedLobby.isFull() && !message.role.equals(RoleEnum.SPECTATOR)) {
@ -100,9 +100,9 @@ public class LobbyManager {
synchronized (lobbies) {
lobbies.put(participant, targetedLobby);
}
if (targetedLobby.isFull() && !LobbyRunner.getInstance().isStarted(targetedLobby)) {
Logger.info("Lobby '{}' was full, starting...", targetedLobby.gameID);
LobbyRunner.getInstance().startLobby(targetedLobby);
if (targetedLobby.isFull()) {
Logger.trace("Lobby is full, checking whether to start lobby or not");
startLobby(targetedLobby);
}
}
return participant;
@ -174,7 +174,14 @@ public class LobbyManager {
}
Logger.trace("Returning local resourceDescriptor");
return localResourceDescriptor;
}
/** Checks whether the current lobby is already started, and if that is not the case, starts it */
private void startLobby(LobbyConnection targetedLobby) {
if (!LobbyRunner.getInstance().isStarted(targetedLobby)) {
Logger.info("Starting Lobby '{}' ...", targetedLobby.gameID);
LobbyRunner.getInstance().startLobby(targetedLobby);
}
}
/** A method to obtain the lobbies HashMap. Meant for testing, and shouldn't be used anywhere else. */