From 15eb18e79a9a6112a81f1d3fb5f91443fad4feaf Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Sat, 5 Jun 2021 19:37:41 +0200 Subject: [PATCH] fix: fixed Participant constructor --- .../server/lobbymanager/Participant.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/Participant.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/Participant.java index cfe9078..307f205 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/Participant.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/Participant.java @@ -1,6 +1,7 @@ package uulm.teamname.marvelous.server.lobbymanager; import org.java_websocket.WebSocket; +import org.tinylog.Logger; import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType; import java.util.Objects; @@ -15,29 +16,34 @@ public class Participant { /** The type (as in role) of participant */ public final ParticipantType type; - /** Whether the participant is an AI */ - public final boolean AI; + /* Whether the participant is an AI */ + // public final boolean AI; /** Creates a new {@link Participant} */ - public Participant (WebSocket connection, ParticipantType type, boolean AI, String name) { + public Participant (WebSocket connection, ParticipantType type, /* boolean AI,*/ String name) { this.connection = connection; this.type = type; - this.AI = AI; + // this.AI = AI; this.name = name; } /** Returns the {@link WebSocket} to contact the participant with */ - public WebSocket getConnection() { + WebSocket getConnection() { return connection; } /** Sets the connection {@link WebSocket} for the current participant */ public void setConnection(WebSocket connection) { + if (this.connection != null) { + Logger.warn("Overriding connection of active participant {}, which seems invalid", this.name); + } + Logger.debug("Setting connection of participant {} to given Websocket {}", this.name, connection); this.connection = connection; } /** Removes reference to current connection from Participant */ public void clearConnection() { + Logger.debug("Setting connection of participant {} to null", this.name); this.connection = null; } @@ -46,20 +52,20 @@ public class Participant { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Participant that = (Participant) o; - return AI == that.AI && Objects.equals(connection, that.connection) && type == that.type; + return Objects.equals(connection, that.connection) && Objects.equals(name, that.name) && type == that.type; } @Override public int hashCode() { - return Objects.hash(connection, type, AI); + return Objects.hash(connection, name, type); } @Override public String toString() { return "Participant{" + "connection=" + connection + + ", name='" + name + '\'' + ", type=" + type + - ", AI=" + AI + '}'; } }