feat: implemented utility methods for LobbyConnection

This commit is contained in:
Yannik Bretschneider 2021-06-01 17:59:29 +02:00
parent 2a4fc1cef0
commit ffb37def47

View File

@ -1,6 +1,7 @@
package uulm.teamname.marvelous.server.lobbymanager;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.gamelogic.ParticipantType;
import uulm.teamname.marvelous.server.lobby.Lobby;
import java.util.HashSet;
@ -37,6 +38,14 @@ public class LobbyConnection {
return player2 != null;
}
public Participant getPlayer1() {
return player1;
}
public Participant getPlayer2() {
return player2;
}
/**
* Adds a new player into the player1 slot
* @param player is the websocket to be added
@ -106,4 +115,24 @@ public class LobbyConnection {
// TODO: implement
MessageRelay.getInstance().broadcastEvents(this, events);
}
public void broadcastToAllExcept(Participant except, Event... events) {
// TODO: implement
var messageRelayInstance = MessageRelay.getInstance();
if (except.type == ParticipantType.Spectator) {
spectators.stream()
.filter(spectator -> !spectator.equals(except))
.forEach(spectator -> messageRelayInstance.sendMessage(this, spectator, events));
messageRelayInstance.sendMessage(this, player1, events);
messageRelayInstance.sendMessage(this, player2, events);
} else {
messageRelayInstance.sendMessage(this, except.equals(player1) ? player2 : player1, events);
spectators.forEach(spectator -> messageRelayInstance.sendMessage(this, spectator, events));
}
}
/** Kills all connections to client, as well as the lobby */
public void terminateConnection() {
MessageRelay.getInstance().terminate(this);
}
}