fix: fixed Participant constructor
This commit is contained in:
parent
30dc25ab2c
commit
15eb18e79a
@ -1,6 +1,7 @@
|
|||||||
package uulm.teamname.marvelous.server.lobbymanager;
|
package uulm.teamname.marvelous.server.lobbymanager;
|
||||||
|
|
||||||
import org.java_websocket.WebSocket;
|
import org.java_websocket.WebSocket;
|
||||||
|
import org.tinylog.Logger;
|
||||||
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -15,29 +16,34 @@ public class Participant {
|
|||||||
/** The type (as in role) of participant */
|
/** The type (as in role) of participant */
|
||||||
public final ParticipantType type;
|
public final ParticipantType type;
|
||||||
|
|
||||||
/** Whether the participant is an AI */
|
/* Whether the participant is an AI */
|
||||||
public final boolean AI;
|
// public final boolean AI;
|
||||||
|
|
||||||
/** Creates a new {@link Participant} */
|
/** 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.connection = connection;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.AI = AI;
|
// this.AI = AI;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the {@link WebSocket} to contact the participant with */
|
/** Returns the {@link WebSocket} to contact the participant with */
|
||||||
public WebSocket getConnection() {
|
WebSocket getConnection() {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the connection {@link WebSocket} for the current participant */
|
/** Sets the connection {@link WebSocket} for the current participant */
|
||||||
public void setConnection(WebSocket connection) {
|
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;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Removes reference to current connection from Participant */
|
/** Removes reference to current connection from Participant */
|
||||||
public void clearConnection() {
|
public void clearConnection() {
|
||||||
|
Logger.debug("Setting connection of participant {} to null", this.name);
|
||||||
this.connection = null;
|
this.connection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,20 +52,20 @@ public class Participant {
|
|||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
Participant that = (Participant) o;
|
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
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(connection, type, AI);
|
return Objects.hash(connection, name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Participant{" +
|
return "Participant{" +
|
||||||
"connection=" + connection +
|
"connection=" + connection +
|
||||||
|
", name='" + name + '\'' +
|
||||||
", type=" + type +
|
", type=" + type +
|
||||||
", AI=" + AI +
|
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user