feat: implemented JSON validation

This commit is contained in:
2021-06-05 15:57:33 +02:00
parent 1f3eb89532
commit e42bce7917
19 changed files with 220 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package uulm.teamname.marvelous.gamelibrary.config;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.constraints.NotEmpty;
import java.util.*;
@ -8,6 +9,8 @@ import java.util.*;
* POJO describing the CharacterConfig as defined by the standard document.
*/
public class CharacterConfig {
@NotEmpty
public CharacterProperties[] characters;
@JsonIgnore private Map<String, CharacterProperties> propertyMap;

View File

@ -2,20 +2,45 @@ package uulm.teamname.marvelous.gamelibrary.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import java.util.Objects;
/** Represents properties of a character in the {@link CharacterConfig} */
@JsonPropertyOrder({"characterID", "name", "HP", "MP", "AP", "meleeDamage", "rangeCombatDamage", "rangeCombatReach"})
public class CharacterProperties {
@NotNull
@Positive
public int characterID;
@NotEmpty
public String name;
@NotNull
@Positive
public int HP;
@NotNull
@Positive
public int MP;
@NotNull
@Positive
public int AP;
@NotNull
@Positive
public int meleeDamage;
@NotNull
@Positive
@JsonProperty("rangeCombatDamage")
public int rangedDamage;
@NotNull
@Positive
@JsonProperty("rangeCombatReach")
public int attackRange;

View File

@ -1,5 +1,7 @@
package uulm.teamname.marvelous.gamelibrary.config;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import java.util.Objects;
/**
@ -7,55 +9,80 @@ import java.util.Objects;
*/
public class PartyConfig {
/** Max round amount in a match */
@NotNull
@Positive
public int maxRounds;
/** Max round time in a match in seconds */
@NotNull
@Positive
public int maxRoundTime;
/** Max overall time in a match in seconds */
@NotNull
@Positive
public int maxGameTime;
/** Max time a single animation might take up in seconds */
@NotNull
@Positive
public int maxAnimationTime;
/** Cooldown of the space stone in rounds */
@NotNull
@Positive
public int spaceStoneCD;
/** Cooldown of the mind stone in rounds */
@NotNull
@Positive
public int mindStoneCD;
/** Cooldown of the reality stone in rounds */
@NotNull
@Positive
public int realityStoneCD;
/** Cooldown of the power stone in rounds */
@NotNull
@Positive
public int powerStoneCD;
/** Cooldown of the time stone in rounds */
@NotNull
@Positive
public int timeStoneCD;
/** Cooldown of the soul stone in rounds */
@NotNull
@Positive
public int soulStoneCD;
/** Damage the mind stone does when used */
@NotNull
@Positive
public int mindStoneDMG;
/** Max pause time. Optional */
@NotNull
@Positive
public int maxPauseTime;
/** Duration that the server waits for the client to respond (send a message), based on the usage of Keep-Alives */
public int maxResponseTime;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PartyConfig that = (PartyConfig) o;
return maxRounds == that.maxRounds && maxRoundTime == that.maxRoundTime && maxGameTime == that.maxGameTime && maxAnimationTime == that.maxAnimationTime && spaceStoneCD == that.spaceStoneCD && mindStoneCD == that.mindStoneCD && realityStoneCD == that.realityStoneCD && powerStoneCD == that.powerStoneCD && timeStoneCD == that.timeStoneCD && soulStoneCD == that.soulStoneCD && mindStoneDMG == that.mindStoneDMG && maxPauseTime == that.maxPauseTime;
return maxRounds == that.maxRounds && maxRoundTime == that.maxRoundTime && maxGameTime == that.maxGameTime && maxAnimationTime == that.maxAnimationTime && spaceStoneCD == that.spaceStoneCD && mindStoneCD == that.mindStoneCD && realityStoneCD == that.realityStoneCD && powerStoneCD == that.powerStoneCD && timeStoneCD == that.timeStoneCD && soulStoneCD == that.soulStoneCD && mindStoneDMG == that.mindStoneDMG && maxPauseTime == that.maxPauseTime && maxResponseTime == that.maxResponseTime;
}
@Override
public int hashCode() {
return Objects.hash(maxRounds, maxRoundTime, maxGameTime, maxAnimationTime, spaceStoneCD, mindStoneCD, realityStoneCD, powerStoneCD, timeStoneCD, soulStoneCD, mindStoneDMG, maxPauseTime);
return Objects.hash(maxRounds, maxRoundTime, maxGameTime, maxAnimationTime, spaceStoneCD, mindStoneCD, realityStoneCD, powerStoneCD, timeStoneCD, soulStoneCD, mindStoneDMG, maxPauseTime, maxResponseTime);
}
@Override
@ -73,6 +100,7 @@ public class PartyConfig {
", soulStoneCD=" + soulStoneCD +
", mindStoneDMG=" + mindStoneDMG +
", maxPauseTime=" + maxPauseTime +
", maxResponseTime=" + maxResponseTime +
'}';
}
}