fix: fixed Participant constructor
This commit is contained in:
parent
30dc25ab2c
commit
15eb18e79a
@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user