improved null safety

main
Jonah Bauer 3 years ago
parent c75cf03762
commit 0f3d3e929d

@ -42,7 +42,7 @@ public class LobbyCommand {
if (count == 1) builder.append("There is one open session:\n");
else builder.append("There are ").append(count).append(" open sessions:\n");
sessions.forEach((session) -> builder.append(session).append('\n'));
sessions.forEach((uuid, session) -> builder.append(session).append('\n'));
client.println(builder);
} else {
client.println("No sessions.");
@ -106,7 +106,7 @@ public class LobbyCommand {
@NotNull
@Override
public Iterator<String> iterator() {
return lobby.getSessions().stream().map(SessionData::getUuid).map(UUID::toString).iterator();
return lobby.getSessions().values().stream().map(SessionData::getUuid).map(UUID::toString).iterator();
}
}
}

@ -10,10 +10,10 @@ import java.util.*;
public final class Lobby extends BaseState {
@Getter
private final Set<SessionData> sessions = new HashSet<>();
private final Map<UUID, SessionData> sessions = new HashMap<>();
public Lobby(SessionListMessage list) {
sessions.addAll(list.getSessions());
list.getSessions().forEach(session -> sessions.put(session.getUuid(), session));
}
@Override
@ -30,18 +30,18 @@ public final class Lobby extends BaseState {
public Optional<ClientState> onMessage(Client client, ServerMessage message) {
if (message instanceof SessionCreatedMessage created) {
var session = created.getSession();
sessions.add(session);
sessions.put(session.getUuid(), session);
return Optional.empty();
} else if (message instanceof SessionRemovedMessage removed) {
sessions.remove(new SessionData(removed.getSession(), null, 0, null));
sessions.remove(removed.getSession());
return Optional.empty();
} else if (message instanceof SessionModifiedMessage modified) {
sessions.remove(modified.getSession());
sessions.add(modified.getSession());
var session = modified.getSession();
sessions.put(session.getUuid(), session);
return Optional.empty();
} else if (message instanceof SessionListMessage list) {
sessions.clear();
sessions.addAll(list.getSessions());
list.getSessions().forEach(session -> sessions.put(session.getUuid(), session));
return Optional.empty();
} else {
return unexpectedMessage(client, message);

@ -8,6 +8,7 @@ import eu.jonahbauer.wizard.client.libgdx.GameAtlas;
import eu.jonahbauer.wizard.common.model.Card;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.EnumMap;
@ -115,23 +116,23 @@ public class CardActor extends Actor {
setOrigin(PREF_WIDTH / 2, PREF_HEIGHT / 2);
}
public CardActor(Card card, TextureAtlas atlas) {
public CardActor(@NotNull Card card, @NotNull TextureAtlas atlas) {
this(atlas);
setCard(card);
}
public CardActor(Card.Suit suit, TextureAtlas atlas) {
public CardActor(@NotNull Card.Suit suit, @NotNull TextureAtlas atlas) {
this(atlas);
setCard(suit);
}
public void setCard(Card card) {
public void setCard(@NotNull Card card) {
this.card = card;
this.background = atlas.findRegion(ATLAS_PATHS.get(card));
if (this.background == null) throw new NoSuchElementException("Could not find texture for card " + card + ".");
}
public void setCard(Card.Suit suit) {
public void setCard(@NotNull Card.Suit suit) {
this.card = null;
this.background = atlas.findRegion(switch (suit) {
case NONE -> GameAtlas.CARDS_BACKGROUND;

@ -13,6 +13,8 @@ import eu.jonahbauer.wizard.client.libgdx.util.Pair;
import eu.jonahbauer.wizard.common.model.Card;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Consumer;
@ -180,7 +182,7 @@ public class CardsGroup extends WidgetGroup {
animate = false;
}
public Pair<List<CardActor>, List<CardActor>> update(List<Card> cards) {
public @NotNull Pair<List<CardActor>, List<CardActor>> update(@NotNull List<Card> cards) {
var added = new ArrayList<>(cards);
var removed = new ArrayList<Card>();
@ -203,7 +205,7 @@ public class CardsGroup extends WidgetGroup {
return Pair.of(removedActors, addedActors);
}
public CardActor remove(Card card) {
public @Nullable CardActor remove(Card card) {
var actor = find(card);
if (actor == null) return null;
@ -223,7 +225,7 @@ public class CardsGroup extends WidgetGroup {
return actor;
}
public CardActor find(Card card) {
public @Nullable CardActor find(Card card) {
var children = getChildren();
for (int i = 0; i < children.size; i++) {
if (children.get(i) instanceof CardActor cardActor && cardActor.getCard() == card) {

@ -4,10 +4,11 @@ import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.common.model.Card;
import org.jetbrains.annotations.NotNull;
public class ChangePredictionOverlay extends MakePredictionOverlay {
public ChangePredictionOverlay(GameScreen gameScreen, long timeout, int round, int oldPrediction) {
public ChangePredictionOverlay(@NotNull GameScreen gameScreen, long timeout, int round, int oldPrediction) {
super(
gameScreen,
timeout,

@ -7,7 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.common.messages.player.PredictMessage;
import org.jetbrains.annotations.NotNull;
import java.util.stream.IntStream;
@ -16,11 +16,11 @@ public class MakePredictionOverlay extends Overlay implements InteractionOverlay
private final int[] values;
private final TextButton[] buttons;
public MakePredictionOverlay(GameScreen gameScreen, long timeout, int round) {
public MakePredictionOverlay(@NotNull GameScreen gameScreen, long timeout, int round) {
this(gameScreen, timeout, IntStream.range(0, round + 2).toArray());
}
protected MakePredictionOverlay(GameScreen gameScreen, long timeout, int[] values) {
protected MakePredictionOverlay(@NotNull GameScreen gameScreen, long timeout, int[] values) {
super(gameScreen, timeout);
this.values = values;
this.buttons = new TextButton[values.length];

@ -13,6 +13,7 @@ import eu.jonahbauer.wizard.client.libgdx.WizardGame;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import lombok.AccessLevel;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
@ -29,7 +30,7 @@ public abstract class Overlay extends Action {
private boolean closing;
private boolean closed;
public Overlay(GameScreen gameScreen, long timeout) {
public Overlay(@NotNull GameScreen gameScreen, long timeout) {
this.screen = gameScreen;
this.data = gameScreen.getData();
this.messages = gameScreen.getMessages();

@ -9,6 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.common.model.Card;
import org.jetbrains.annotations.NotNull;
import java.util.EnumMap;
@ -18,7 +19,7 @@ public class PickTrumpOverlay extends Overlay implements InteractionOverlay {
private final EnumMap<Card.Suit, CardActor> cards = new EnumMap<>(Card.Suit.class);
public PickTrumpOverlay(GameScreen gameScreen, long timeout, boolean allowNone) {
public PickTrumpOverlay(@NotNull GameScreen gameScreen, long timeout, boolean allowNone) {
super(gameScreen, timeout);
this.allowNone = allowNone;
}

@ -11,6 +11,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.common.model.Card;
import org.jetbrains.annotations.NotNull;
import java.util.EnumMap;
@ -21,7 +22,9 @@ public class PlayColoredCardOverlay extends Overlay implements InteractionOverla
private final Card card;
public PlayColoredCardOverlay(GameScreen gameScreen, long timeout, Card card, Card red, Card green, Card blue, Card yellow) {
public PlayColoredCardOverlay(@NotNull GameScreen gameScreen, long timeout, @NotNull Card card,
@NotNull Card red, @NotNull Card green, @NotNull Card blue, @NotNull Card yellow)
{
super(gameScreen, timeout);
this.card = card;
this.cards.put(Card.Suit.RED, red);

@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import eu.jonahbauer.wizard.client.libgdx.AnimationTimings;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import org.jetbrains.annotations.NotNull;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
@ -13,7 +14,7 @@ public class StartRoundOverlay extends Overlay {
private final int round;
public StartRoundOverlay(GameScreen gameScreen, int round) {
public StartRoundOverlay(@NotNull GameScreen gameScreen, int round) {
super(gameScreen, Long.MAX_VALUE);
this.round = round;
}

@ -12,8 +12,11 @@ import eu.jonahbauer.wizard.client.libgdx.actions.MyActions;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.common.model.Card;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Objects;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import static eu.jonahbauer.wizard.client.libgdx.actions.MyActions.*;
@ -81,22 +84,22 @@ public class TrumpOverlay extends Overlay {
Map.entry(Card.FAIRY, Card.Suit.NONE)
);
private final String player;
private final Card card;
private final Card.Suit suit;
private final @Nullable String player;
private final @NotNull Card card;
private final @Nullable Card.Suit suit;
private final CardActor trumpCardActor;
private final CardActor trumpSuitActor;
private final @NotNull CardActor trumpCardActor;
private final @NotNull CardActor trumpSuitActor;
private boolean animateCard = true;
public TrumpOverlay(GameScreen gameScreen, String player, Card card, Card.Suit suit) {
public TrumpOverlay(@NotNull GameScreen gameScreen, @Nullable String player, @NotNull Card card, @Nullable Card.Suit suit) {
super(gameScreen, Long.MAX_VALUE);
this.player = player;
this.card = card;
this.suit = suit;
this.trumpCardActor = gameScreen.getTrumpCardActor();
this.trumpSuitActor = gameScreen.getTrumpSuitActor();
this.trumpCardActor = Objects.requireNonNull(gameScreen.getTrumpCardActor());
this.trumpSuitActor = Objects.requireNonNull(gameScreen.getTrumpSuitActor());
}
@Override
@ -141,7 +144,7 @@ public class TrumpOverlay extends Overlay {
}
trumpSuitActor.remove();
if (suit != DEFAULT_SUITES.get(card)) {
if (suit != null && suit != DEFAULT_SUITES.get(card)) {
trumpSuitActor.setRotation(0);
trumpSuitActor.setOrigin(0, 0);
cardGroup.addActor(trumpSuitActor);
@ -164,7 +167,7 @@ public class TrumpOverlay extends Overlay {
));
}
if (suit != DEFAULT_SUITES.get(card)) {
if (suit != null && suit != DEFAULT_SUITES.get(card)) {
cardAnimation.addAction(sequence(
targeting(trumpSuitActor, removeActorSilently()),
targeting(trumpSuitActor, changeParent(parent)),

@ -203,11 +203,11 @@ public class GameScreen extends MenuScreen {
return self.equals(uuid);
}
public void onCardClicked(Card card) {
public void onCardClicked(@NotNull Card card) {
game.getClient().execute(Game.class, (s, c) -> s.onCardClicked(c, card));
}
public void onSuitClicked(Card.Suit suit) {
public void onSuitClicked(@NotNull Card.Suit suit) {
game.getClient().execute(Game.class, (s, c) -> s.onSuitClicked(c, suit));
}
@ -241,7 +241,7 @@ public class GameScreen extends MenuScreen {
execute(() -> cardStack.clearChildren());
}
public void finishTrick(UUID player) {
public void finishTrick(@NotNull UUID player) {
var seat = seats.getOrDefault(player, Seat.FALLBACK);
var action = parallel();
@ -272,7 +272,7 @@ public class GameScreen extends MenuScreen {
/**
* Updates the given players hand cards.
*/
public void setHand(UUID player, List<Card> cards, boolean juggle) {
public void setHand(@NotNull UUID player, @NotNull List<Card> cards, boolean juggle) {
if (isSelf(player)) {
var sequence = sequence();
sequence.addAction(run(() -> {
@ -291,7 +291,7 @@ public class GameScreen extends MenuScreen {
* Adds the prediction for the given round and player to the {@linkplain #padOfTruth pad of truth} and
* shows a corresponding message.
*/
public void addPrediction(int round, UUID player, int prediction, boolean changed) {
public void addPrediction(int round, @NotNull UUID player, int prediction, boolean changed) {
if (isSelf(player)) {
addMessage(game.messages.format("game.action." + (changed ? "change" : "make") + "_prediction.self", prediction));
} else {
@ -299,13 +299,16 @@ public class GameScreen extends MenuScreen {
addMessage(game.messages.format("game.action." + (changed ? "change" : "make") + "_prediction.other", name, prediction));
}
execute(() -> padOfTruth.setPrediction(orderedPlayers.indexOf(player), round, prediction));
var index = orderedPlayers.indexOf(player);
if (index == -1) throw new NoSuchElementException();
execute(() -> padOfTruth.setPrediction(index, round, prediction));
}
/**
* Removes the card from the players hand and puts it into the {@linkplain #cardStack stack}.
*/
public void playCard(UUID player, Card card) {
public void playCard(@NotNull UUID player, @NotNull Card card) {
if (isSelf(player)) {
addMessage(game.messages.get("game.action.play_card.self"));
} else {
@ -336,11 +339,11 @@ public class GameScreen extends MenuScreen {
/**
* Adds the scores for a round to the corresponding row of the {@linkplain #padOfTruth pad of truth}.
*/
public void addScores(int round, Map<UUID, Integer> scores) {
public void addScores(int round, @NotNull Map<UUID, Integer> scores) {
execute(() -> {
for (int i = 0; i < orderedPlayers.size(); i++) {
UUID player = orderedPlayers.get(i);
padOfTruth.setScore(i, round, scores.get(player));
padOfTruth.setScore(i, round, scores.getOrDefault(player, 0));
}
});
}
@ -356,10 +359,10 @@ public class GameScreen extends MenuScreen {
* Highlights the given players label and sets the {@linkplain #setPersistentMessage(String) persistent message}
* accordingly.
*/
public void setActivePlayer(UUID player, UserInputMessage.Action action, long timeout) {
public void setActivePlayer(@Nullable UUID player, @Nullable UserInputMessage.Action action, long timeout) {
execute(() -> nameLabels.forEach((p, l) -> l.setStyle(p.equals(player) ? labelStyleActive : labelStyleDefault)));
if (isSelf(player) || player == null && action == null) {
if (isSelf(player) || action == null) {
setPersistentMessage(null);
} else {
var key = switch (action) {
@ -390,7 +393,7 @@ public class GameScreen extends MenuScreen {
* Swaps the current {@linkplain #trumpCardActor trump card} (if present) with a {@linkplain Card#WEREWOLF werewolf}
* card on the given players hand.
*/
public void swapTrumpCard(UUID player) {
public void swapTrumpCard(@NotNull UUID player) {
var seat = seats.getOrDefault(player, Seat.FALLBACK);
var sequence = sequence();
@ -448,7 +451,7 @@ public class GameScreen extends MenuScreen {
}
//<editor-fold desc="Overlays" defaultstate="collapsed">
public void showTrumpOverlay(UUID player, Card trumpCard, Card.Suit trumpSuit) {
public void showTrumpOverlay(@Nullable UUID player, @NotNull Card trumpCard, @Nullable Card.Suit trumpSuit) {
if (trumpCardActor == null) {
trumpCardActor = new CardActor(Card.HIDDEN, atlas);
}
@ -460,7 +463,7 @@ public class GameScreen extends MenuScreen {
execute(new TrumpOverlay(this, players.get(player), trumpCard, trumpSuit));
}
public void showColoredCardOverlay(Card card, long timeout) {
public void showColoredCardOverlay(@NotNull Card card, long timeout) {
if (card == Card.JUGGLER) {
execute(new PlayColoredCardOverlay(this, timeout, card, Card.JUGGLER_RED, Card.JUGGLER_GREEN, Card.JUGGLER_BLUE, Card.JUGGLER_YELLOW));
} else if (card == Card.CLOUD) {
@ -587,7 +590,7 @@ public class GameScreen extends MenuScreen {
return game.messages;
}
private Action animateJuggle(List<CardActor> removed, List<CardActor> added) {
private Action animateJuggle(@NotNull List<CardActor> removed, @NotNull List<CardActor> added) {
// find left- and rightmost seat
Seat tmpLeft = null, tmpRight = null;
for (Seat seat : seats.values()) {

@ -3,8 +3,8 @@ package eu.jonahbauer.wizard.common.messages.client;
import eu.jonahbauer.wizard.common.model.Configuration;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.Range;
@Getter
@RequiredArgsConstructor
@ -13,11 +13,11 @@ public final class CreateSessionMessage extends ClientMessage {
/**
* Name of the session
*/
private final String sessionName;
private final @NonNull String sessionName;
/**
* Name of the creating and joining player
*/
private final String playerName;
private final @NonNull String playerName;
/**
* timout in milliseconds for user interactions
*/
@ -25,5 +25,5 @@ public final class CreateSessionMessage extends ClientMessage {
/**
* Game configuration
*/
private final Configuration configuration;
private final @NonNull Configuration configuration;
}

@ -3,6 +3,7 @@ package eu.jonahbauer.wizard.common.messages.client;
import eu.jonahbauer.wizard.common.messages.player.PlayerMessage;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Getter
@ -12,5 +13,5 @@ public final class InteractionMessage extends ClientMessage {
/**
* Wrapped {@link PlayerMessage}
*/
private final PlayerMessage playerMessage;
private final @NonNull PlayerMessage playerMessage;
}

@ -2,6 +2,7 @@ package eu.jonahbauer.wizard.common.messages.client;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.UUID;
@ -13,9 +14,9 @@ public final class JoinSessionMessage extends ClientMessage {
/**
* UUID of the session
*/
private final UUID session;
private final @NonNull UUID session;
/**
* Name of the joining player
*/
private final String playerName;
private final @NonNull String playerName;
}

@ -2,6 +2,7 @@ package eu.jonahbauer.wizard.common.messages.client;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.UUID;
@ -13,13 +14,13 @@ public final class RejoinMessage extends ClientMessage {
/**
* UUID of the session
*/
private final UUID session;
private final @NonNull UUID session;
/**
* UUID of the rejoining player
*/
private final UUID player;
private final @NonNull UUID player;
/**
* Secret in order to assure that no malicious user wants to join the message
*/
private final String secret;
private final @NonNull String secret;
}

@ -1,9 +1,6 @@
package eu.jonahbauer.wizard.common.messages.data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.*;
import java.util.UUID;
@ -15,11 +12,11 @@ public class PlayerData {
/**
* UUID of the player
*/
private final UUID uuid;
private final @NonNull UUID uuid;
/**
* Name of the player
*/
private final String name;
private final @NonNull String name;
/**
* Readiness state of the player
*/

@ -1,10 +1,7 @@
package eu.jonahbauer.wizard.common.messages.data;
import eu.jonahbauer.wizard.common.model.Configuration;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.*;
import java.util.UUID;
@ -16,11 +13,11 @@ public class SessionData {
/**
* UUID of the session
*/
private final UUID uuid;
private final @NonNull UUID uuid;
/**
* Name of the session
*/
private final String name;
private final @NonNull String name;
/**
* Number of players currently in the session
*/
@ -28,5 +25,5 @@ public class SessionData {
/**
* Configuration of the session
*/
private final Configuration configuration;
private final @NonNull Configuration configuration;
}

@ -3,8 +3,8 @@ package eu.jonahbauer.wizard.common.messages.observer;
import eu.jonahbauer.wizard.common.model.Card;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
@ -18,9 +18,9 @@ public final class CardMessage extends ObserverMessage {
/**
* The UUID of the player.
*/
private final @NotNull UUID player;
private final @NonNull UUID player;
/**
* The card played.
*/
private final @NotNull Card card;
private final @NonNull Card card;
}

@ -3,7 +3,9 @@ package eu.jonahbauer.wizard.common.messages.observer;
import eu.jonahbauer.wizard.common.model.Card;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
import java.util.List;
import java.util.UUID;
@ -17,14 +19,14 @@ public final class HandMessage extends ObserverMessage {
/**
* The UUID of player whose hand cards are sent.
*/
private final @NotNull UUID player;
private final @NonNull UUID player;
/**
* A list of all the hand cards. May consist only of {@link Card#HIDDEN} if the cards are not visible to the player
* receiving this message.
*/
private final @NotNull List<@NotNull Card> hand;
private final @Unmodifiable @NonNull List<@NotNull Card> hand;
public HandMessage(@NotNull UUID player, @NotNull List<@NotNull Card> hand) {
public HandMessage(@NonNull UUID player, @NonNull List<@NonNull Card> hand) {
this.player = player;
this.hand = List.copyOf(hand);
}

@ -2,8 +2,7 @@ package eu.jonahbauer.wizard.common.messages.observer;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import lombok.NonNull;
import org.jetbrains.annotations.Range;
import java.util.UUID;
@ -12,15 +11,20 @@ import java.util.UUID;
* A {@link PredictionMessage} is sent after a player makes (or changes) his prediction.
*/
@Getter
@RequiredArgsConstructor
@EqualsAndHashCode(callSuper = true)
public final class PredictionMessage extends ObserverMessage {
/**
* The UUID of the player who made a prediction.
*/
private final @NotNull UUID player;
private final @NonNull UUID player;
/**
* The prediction.
*/
private final @Range(from = 0, to = Integer.MAX_VALUE) int prediction;
public PredictionMessage(@NonNull UUID player, int prediction) {
if (prediction < 0) throw new IllegalArgumentException("prediction is out of bounds");
this.player = player;
this.prediction = prediction;
}
}

@ -2,7 +2,9 @@ package eu.jonahbauer.wizard.common.messages.observer;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
import java.util.Map;
import java.util.UUID;
@ -17,9 +19,9 @@ public final class ScoreMessage extends ObserverMessage {
/**
* The number of points for each player.
*/
private final @NotNull Map<@NotNull UUID, @NotNull Integer> points;
private final @Unmodifiable @NonNull Map<@NonNull UUID, @NonNull Integer> points;
public ScoreMessage(@NotNull Map<@NotNull UUID, @NotNull Integer> points) {
public ScoreMessage(@NonNull Map<@NonNull UUID, @NonNull Integer> points) {
this.points = Map.copyOf(points);
}
}

@ -2,7 +2,9 @@ package eu.jonahbauer.wizard.common.messages.observer;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
/**
* A {@link StateMessage} is sent whenever the game changes its internal state.
@ -14,5 +16,5 @@ public final class StateMessage extends ObserverMessage {
/**
* The name of the new state in snake_case.
*/
private final String state;
private final @NonNull String state;
}

@ -3,6 +3,8 @@ package eu.jonahbauer.wizard.common.messages.observer;
import eu.jonahbauer.wizard.common.model.Card;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import org.jetbrains.annotations.Unmodifiable;
import java.util.List;
import java.util.UUID;
@ -17,13 +19,13 @@ public final class TrickMessage extends ObserverMessage {
/**
* The UUID of the player who won the trick.
*/
private final UUID player;
private final @NonNull UUID player;
/**
* The cards played.
*/
private final List<Card> cards;
private final @Unmodifiable @NonNull List<@NonNull Card> cards;
public TrickMessage(UUID player, List<Card> cards) {
public TrickMessage(@NonNull UUID player, @NonNull List<@NonNull Card> cards) {
this.player = player;
this.cards = List.copyOf(cards);
}

@ -7,7 +7,9 @@ import eu.jonahbauer.wizard.common.messages.player.PredictMessage;
import eu.jonahbauer.wizard.common.model.Card;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
@ -22,11 +24,11 @@ public final class UserInputMessage extends ObserverMessage {
* The UUID of the player whose input is required. May be {@code null} to indicate that an input is required from
* every player.
*/
private final UUID player;
private final @Nullable UUID player;
/**
* The type of input that is required.
*/
private final Action action;
private final @NonNull Action action;
/**
* A timeout in {@link System#currentTimeMillis() UNIX time} after which a default action is taken.
*/

@ -3,11 +3,12 @@ package eu.jonahbauer.wizard.common.messages.player;
import eu.jonahbauer.wizard.common.model.Card;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
@EqualsAndHashCode(callSuper = true)
public final class JuggleMessage extends PlayerMessage {
private final Card card;
private final @NonNull Card card;
}

@ -3,11 +3,12 @@ package eu.jonahbauer.wizard.common.messages.player;
import eu.jonahbauer.wizard.common.model.Card;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
@EqualsAndHashCode(callSuper = true)
public final class PickTrumpMessage extends PlayerMessage {
private final Card.Suit trumpSuit;
private final @NonNull Card.Suit trumpSuit;
}

@ -3,11 +3,12 @@ package eu.jonahbauer.wizard.common.messages.player;
import eu.jonahbauer.wizard.common.model.Card;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
@EqualsAndHashCode(callSuper = true)
public final class PlayCardMessage extends PlayerMessage {
private final Card card;
private final @NonNull Card card;
}

@ -3,6 +3,7 @@ package eu.jonahbauer.wizard.common.messages.server;
import eu.jonahbauer.wizard.common.messages.observer.ObserverMessage;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Getter
@ -12,5 +13,5 @@ public final class GameMessage extends ServerMessage {
/**
* Wrapped {@link ObserverMessage}
*/
private final ObserverMessage observerMessage;
private final @NonNull ObserverMessage observerMessage;
}

@ -2,6 +2,7 @@ package eu.jonahbauer.wizard.common.messages.server;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.UUID;
@ -13,11 +14,11 @@ public final class KickVotedMessage extends ServerMessage {
/**
* UUID of the voting player
*/
private final UUID voter;
private final @NonNull UUID voter;
/**
* UUID of player who is supposed to be kicked
*/
private final UUID player;
private final @NonNull UUID player;
/**
* Time until the vote ends in {@link System#currentTimeMillis() UNIX time}
*/

@ -2,6 +2,7 @@ package eu.jonahbauer.wizard.common.messages.server;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.UUID;
@ -13,5 +14,5 @@ public final class KickedMessage extends ServerMessage {
/**
* UUID of player who was kicked
*/
private final UUID player;
private final @NonNull UUID player;
}

@ -2,6 +2,7 @@ package eu.jonahbauer.wizard.common.messages.server;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import org.intellij.lang.annotations.MagicConstant;
@Getter
@ -26,9 +27,9 @@ public final class NackMessage extends ServerMessage implements Response {
public static final int BAD_REQUEST = 999;
private final int code;
private final String message;
private final @NonNull String message;
public NackMessage(@MagicConstant(valuesFromClass = NackMessage.class) int code, String message) {
public NackMessage(@MagicConstant(valuesFromClass = NackMessage.class) int code, @NonNull String message) {
this.code = code;
this.message = message;
}

@ -2,11 +2,12 @@ package eu.jonahbauer.wizard.common.messages.server;
import eu.jonahbauer.wizard.common.messages.data.PlayerData;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
@EqualsAndHashCode(callSuper = true)
public final class PlayerJoinedMessage extends PlayerModifiedMessage {
public PlayerJoinedMessage(PlayerData playerData) {
super(playerData);
public PlayerJoinedMessage(@NonNull PlayerData player) {
super(player);
}
}

@ -2,6 +2,7 @@ package eu.jonahbauer.wizard.common.messages.server;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.UUID;
@ -13,5 +14,5 @@ public final class PlayerLeftMessage extends ServerMessage {
/**
* UUID of player who has left
*/
private final UUID player;
private final @NonNull UUID player;
}

@ -3,6 +3,7 @@ package eu.jonahbauer.wizard.common.messages.server;
import eu.jonahbauer.wizard.common.messages.data.PlayerData;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Getter
@ -12,5 +13,5 @@ public sealed class PlayerModifiedMessage extends ServerMessage permits PlayerJo
/**
* Joining player
*/
private final PlayerData player;
private final @NonNull PlayerData player;
}

@ -2,11 +2,12 @@ package eu.jonahbauer.wizard.common.messages.server;
import eu.jonahbauer.wizard.common.messages.data.SessionData;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
@EqualsAndHashCode(callSuper = true)
public final class SessionCreatedMessage extends SessionModifiedMessage {
public SessionCreatedMessage(SessionData session) {
public SessionCreatedMessage(@NonNull SessionData session) {
super(session);
}
}

@ -3,6 +3,8 @@ package eu.jonahbauer.wizard.common.messages.server;
import eu.jonahbauer.wizard.common.messages.data.PlayerData;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import org.jetbrains.annotations.Unmodifiable;
import java.util.List;
import java.util.UUID;
@ -13,21 +15,21 @@ public final class SessionJoinedMessage extends ServerMessage implements Respons
/**
* UUID of joined session
*/
private final UUID session;
private final @NonNull UUID session;
/**
* UUID assigned to the player
*/
private final UUID player;
private final @NonNull UUID player;
/**
* List of players already in the session
*/
private final List<PlayerData> players;
private final @Unmodifiable @NonNull List<@NonNull PlayerData> players;
/**
* Secret notified to player in order to ensure that if necessary the correct player rejoins
*/
private final String secret;
private final @NonNull String secret;
public SessionJoinedMessage(UUID session, UUID player, List<PlayerData> players, String secret) {
public SessionJoinedMessage(@NonNull UUID session, @NonNull UUID player, @NonNull List<@NonNull PlayerData> players, @NonNull String secret) {
this.session = session;
this.player = player;
this.players = List.copyOf(players);

@ -3,6 +3,8 @@ package eu.jonahbauer.wizard.common.messages.server;
import eu.jonahbauer.wizard.common.messages.data.SessionData;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import org.jetbrains.annotations.Unmodifiable;
import java.util.List;
@ -12,9 +14,9 @@ public final class SessionListMessage extends ServerMessage implements Response
/**
* List of available sessions
*/
private final List<SessionData> sessions;
private final @Unmodifiable @NonNull List<@NonNull SessionData> sessions;
public SessionListMessage(List<SessionData> sessions) {
public SessionListMessage(@NonNull List<@NonNull SessionData> sessions) {
this.sessions = List.copyOf(sessions);
}
}

@ -3,6 +3,7 @@ package eu.jonahbauer.wizard.common.messages.server;
import eu.jonahbauer.wizard.common.messages.data.SessionData;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Getter
@ -12,5 +13,5 @@ public sealed class SessionModifiedMessage extends ServerMessage permits Session
/**
* The created session
*/
private final SessionData session;
private final @NonNull SessionData session;
}

@ -2,6 +2,7 @@ package eu.jonahbauer.wizard.common.messages.server;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.UUID;
@ -13,5 +14,5 @@ public final class SessionRemovedMessage extends ServerMessage {
/**
* UUID of the removed session
*/
private final UUID session;
private final @NonNull UUID session;
}

Loading…
Cancel
Save