fix: stop making duplicate properties which are difficult to access

This commit is contained in:
punchready 2021-06-29 08:38:04 +02:00
parent be7dd1ca94
commit bc3319eed0
13 changed files with 52 additions and 30 deletions

View File

@ -1,13 +1,9 @@
package uulm.teamname.marvelous.gamelibrary.messages;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
public class ErrorMessage extends BasicMessage{
public final MessageType messageType = MessageType.ERROR;
/** Some message telling the client what went wrong */
@NotNull
public String message = "No message given";
@ -15,4 +11,8 @@ public class ErrorMessage extends BasicMessage{
/** The type of the error that happened */
@NotNull
public int type = 0;
public ErrorMessage() {
messageType = MessageType.ERROR;
}
}

View File

@ -9,8 +9,6 @@ import java.util.Arrays;
public class CharacterSelectionMessage extends BasicMessage {
public final MessageType messageType = MessageType.CHARACTER_SELECTION;
/**
* Boolean array that conveys information about what characters (6)
* of the given characters (12) have been selected
@ -19,6 +17,10 @@ public class CharacterSelectionMessage extends BasicMessage {
@Size(min = 12, max = 12, message = "doesn't have twelve elements")
public Boolean[] characters;
public CharacterSelectionMessage() {
messageType = MessageType.CHARACTER_SELECTION;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -4,12 +4,8 @@ import jakarta.validation.constraints.NotEmpty;
import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage;
import uulm.teamname.marvelous.gamelibrary.messages.MessageType;
import jakarta.validation.constraints.NotNull;
public class HelloServerMessage extends BasicMessage {
public final MessageType messageType = MessageType.HELLO_SERVER;
/** User-chosen name, basically a PlayerName */
@NotEmpty
public String name;
@ -17,4 +13,8 @@ public class HelloServerMessage extends BasicMessage {
/** Device ID sent by the Client, might be anything, but used together with name to uniquely identify the client */
@NotEmpty
public String deviceID;
public HelloServerMessage() {
messageType = MessageType.HELLO_SERVER;
}
}

View File

@ -8,8 +8,6 @@ import jakarta.validation.constraints.NotNull;
public class PlayerReadyMessage extends BasicMessage {
public final MessageType messageType = MessageType.PLAYER_READY;
/** Whether the client wants to start the game. If this is false, the client gets disconnected. */
@NotNull
public Boolean startGame;
@ -17,4 +15,8 @@ public class PlayerReadyMessage extends BasicMessage {
/** The {@link RoleEnum Role} the client wants to take */
@NotNull
public RoleEnum role;
public PlayerReadyMessage() {
messageType = MessageType.PLAYER_READY;
}
}

View File

@ -7,9 +7,11 @@ import jakarta.validation.constraints.NotNull;
public class ReconnectMessage extends BasicMessage {
public final MessageType messageType = MessageType.RECONNECT;
/** Whether the client wants to reconnect to the previously running game */
@NotNull
public Boolean reconnect;
public ReconnectMessage() {
messageType = MessageType.RECONNECT;
}
}

View File

@ -15,8 +15,6 @@ import java.util.Objects;
/** Represents a message sent between client and server and contains all possible data. */
public class RequestMessage extends BasicMessage {
public final MessageType messageType = MessageType.REQUESTS;
/** The list of {@link Event Events} sent inside the message. */
@NotNull(message = "No Requests found")
@NotEmpty(message = "No Requests found")
@ -28,6 +26,10 @@ public class RequestMessage extends BasicMessage {
/** The decoded contents of the custom content sent. */
public HashMap<String, Object> customContent;
public RequestMessage() {
messageType = MessageType.REQUESTS;
}
@Override @JsonIgnore
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -8,12 +8,14 @@ import java.util.Objects;
public class ConfirmSelectionMessage extends BasicMessage {
public final MessageType messageType = MessageType.CONFIRM_SELECTION;
/** Whether the other player is also done with the selection already */
@NotNull
public Boolean selectionComplete;
public ConfirmSelectionMessage() {
messageType = MessageType.CONFIRM_SELECTION;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -15,8 +15,6 @@ import java.util.Objects;
// @JsonDeserialize(using = EventMessageDeserializer.class)
public class EventMessage extends BasicMessage {
public final MessageType messageType = MessageType.EVENTS;
/** The list of {@link Event Events} sent inside the message. */
@NotNull(message = "No events found")
@NotEmpty(message = "No events found")
@ -28,6 +26,10 @@ public class EventMessage extends BasicMessage {
/** The decoded contents of the custom content sent. */
public HashMap<String, Object> customContent;
public EventMessage() {
messageType = MessageType.EVENTS;
}
@Override @JsonIgnore
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -13,8 +13,6 @@ import java.util.Objects;
// @JsonDeserialize(using = GameAssignmentDeserializer.class)
public class GameAssignmentMessage extends BasicMessage {
public final MessageType messageType = MessageType.GAME_ASSIGNMENT;
/** The ID of the game that the client is connected to. What this is used for is kind of unknown. */
@NotEmpty
public String gameID;
@ -24,6 +22,10 @@ public class GameAssignmentMessage extends BasicMessage {
@Size(min = 12, max = 12, message = "Character Selection doesn't have 12 booleans")
public CharacterProperties[] characterSelection;
public GameAssignmentMessage() {
messageType = MessageType.GAME_ASSIGNMENT;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -28,8 +28,6 @@ import java.util.stream.Stream;
"matchconfig"})
public class GameStructureMessage extends BasicMessage {
public final MessageType messageType = MessageType.GAME_STRUCTURE;
/** The role the client has been assigned to */
@NotNull
public ParticipantType assignment;
@ -63,6 +61,10 @@ public class GameStructureMessage extends BasicMessage {
@Valid
public ScenarioConfig scenarioconfig;
public GameStructureMessage() {
messageType = MessageType.GAME_STRUCTURE;
}
@JsonIgnore public CharacterConfig getCharacterConfig() {
CharacterConfig characterConfig = new CharacterConfig();
characterConfig.characters = Stream

View File

@ -9,13 +9,15 @@ import java.util.Objects;
public class GeneralAssignmentMessage extends BasicMessage {
public final MessageType messageType = MessageType.GENERAL_ASSIGNMENT;
/** The ID of the game that the client is connected to. What this is used for is kind of unknown. */
@NotNull
@NotEmpty
public String gameID;
public GeneralAssignmentMessage() {
messageType = MessageType.GENERAL_ASSIGNMENT;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -8,9 +8,11 @@ import jakarta.validation.constraints.NotNull;
public class GoodbyeClientMessage extends BasicMessage {
public final MessageType messageType = MessageType.GOODBYE_CLIENT;
/** A message sent to the client on disconnect */
@NotEmpty
public String message = "You got disconnected.";
public GoodbyeClientMessage() {
messageType = MessageType.GOODBYE_CLIENT;
}
}

View File

@ -7,9 +7,11 @@ import jakarta.validation.constraints.NotNull;
public class HelloClientMessage extends BasicMessage {
public final MessageType messageType = MessageType.HELLO_CLIENT;
/** Whether there is a running game that the player disconnected from */
@NotNull
public Boolean runningGame;
public HelloClientMessage() {
messageType = MessageType.HELLO_CLIENT;
}
}