From 0f3d3e929d14b407d67f538ca8465d996c999d57 Mon Sep 17 00:00:00 2001 From: Jonah Bauer Date: Wed, 12 Jan 2022 11:35:02 +0100 Subject: [PATCH] improved null safety --- .../client/cli/commands/LobbyCommand.java | 4 +-- .../wizard/client/cli/state/Lobby.java | 14 ++++---- .../client/libgdx/actors/game/CardActor.java | 9 ++--- .../client/libgdx/actors/game/CardsGroup.java | 8 +++-- .../game/overlay/ChangePredictionOverlay.java | 3 +- .../game/overlay/MakePredictionOverlay.java | 6 ++-- .../libgdx/actors/game/overlay/Overlay.java | 3 +- .../actors/game/overlay/PickTrumpOverlay.java | 3 +- .../game/overlay/PlayColoredCardOverlay.java | 5 ++- .../game/overlay/StartRoundOverlay.java | 3 +- .../actors/game/overlay/TrumpOverlay.java | 23 +++++++------ .../client/libgdx/screens/GameScreen.java | 33 ++++++++++--------- .../messages/client/CreateSessionMessage.java | 8 ++--- .../messages/client/InteractionMessage.java | 3 +- .../messages/client/JoinSessionMessage.java | 5 +-- .../common/messages/client/RejoinMessage.java | 7 ++-- .../common/messages/data/PlayerData.java | 9 ++--- .../common/messages/data/SessionData.java | 11 +++---- .../common/messages/observer/CardMessage.java | 6 ++-- .../common/messages/observer/HandMessage.java | 8 +++-- .../messages/observer/PredictionMessage.java | 12 ++++--- .../messages/observer/ScoreMessage.java | 6 ++-- .../messages/observer/StateMessage.java | 4 ++- .../messages/observer/TrickMessage.java | 8 +++-- .../messages/observer/UserInputMessage.java | 6 ++-- .../common/messages/player/JuggleMessage.java | 3 +- .../messages/player/PickTrumpMessage.java | 3 +- .../messages/player/PlayCardMessage.java | 3 +- .../common/messages/server/GameMessage.java | 3 +- .../messages/server/KickVotedMessage.java | 5 +-- .../common/messages/server/KickedMessage.java | 3 +- .../common/messages/server/NackMessage.java | 5 +-- .../messages/server/PlayerJoinedMessage.java | 5 +-- .../messages/server/PlayerLeftMessage.java | 3 +- .../server/PlayerModifiedMessage.java | 3 +- .../server/SessionCreatedMessage.java | 3 +- .../messages/server/SessionJoinedMessage.java | 12 ++++--- .../messages/server/SessionListMessage.java | 6 ++-- .../server/SessionModifiedMessage.java | 3 +- .../server/SessionRemovedMessage.java | 3 +- 40 files changed, 157 insertions(+), 113 deletions(-) diff --git a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/commands/LobbyCommand.java b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/commands/LobbyCommand.java index bb1b57a..4aaa13d 100644 --- a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/commands/LobbyCommand.java +++ b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/commands/LobbyCommand.java @@ -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 iterator() { - return lobby.getSessions().stream().map(SessionData::getUuid).map(UUID::toString).iterator(); + return lobby.getSessions().values().stream().map(SessionData::getUuid).map(UUID::toString).iterator(); } } } diff --git a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/state/Lobby.java b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/state/Lobby.java index 3f716eb..619ba71 100644 --- a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/state/Lobby.java +++ b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/state/Lobby.java @@ -10,10 +10,10 @@ import java.util.*; public final class Lobby extends BaseState { @Getter - private final Set sessions = new HashSet<>(); + private final Map 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 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); diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/CardActor.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/CardActor.java index 9113f59..cceb153 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/CardActor.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/CardActor.java @@ -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; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/CardsGroup.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/CardsGroup.java index 553e7cc..877e439 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/CardsGroup.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/CardsGroup.java @@ -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> update(List cards) { + public @NotNull Pair, List> update(@NotNull List cards) { var added = new ArrayList<>(cards); var removed = new ArrayList(); @@ -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) { diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/ChangePredictionOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/ChangePredictionOverlay.java index 4fb08ec..a4a8160 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/ChangePredictionOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/ChangePredictionOverlay.java @@ -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, diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/MakePredictionOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/MakePredictionOverlay.java index 8805def..7c4acb3 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/MakePredictionOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/MakePredictionOverlay.java @@ -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]; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/Overlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/Overlay.java index ebf375e..2ece58b 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/Overlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/Overlay.java @@ -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(); diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/PickTrumpOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/PickTrumpOverlay.java index cacd76b..c3d47f6 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/PickTrumpOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/PickTrumpOverlay.java @@ -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 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; } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/PlayColoredCardOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/PlayColoredCardOverlay.java index ea0e0d8..e584258 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/PlayColoredCardOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/PlayColoredCardOverlay.java @@ -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); diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/StartRoundOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/StartRoundOverlay.java index 42bc186..6b99a5c 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/StartRoundOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/StartRoundOverlay.java @@ -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; } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/TrumpOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/TrumpOverlay.java index b120b80..045e546 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/TrumpOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/game/overlay/TrumpOverlay.java @@ -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)), diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java index ab5b343..8fbe247 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java @@ -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 cards, boolean juggle) { + public void setHand(@NotNull UUID player, @NotNull List 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 scores) { + public void addScores(int round, @NotNull Map 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 { } // - 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 removed, List added) { + private Action animateJuggle(@NotNull List removed, @NotNull List added) { // find left- and rightmost seat Seat tmpLeft = null, tmpRight = null; for (Seat seat : seats.values()) { diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/CreateSessionMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/CreateSessionMessage.java index cb7e16e..0ba5ebe 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/CreateSessionMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/CreateSessionMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/InteractionMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/InteractionMessage.java index 97d04a7..5dc86d3 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/InteractionMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/InteractionMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/JoinSessionMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/JoinSessionMessage.java index 5bc1e33..439aabe 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/JoinSessionMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/JoinSessionMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/RejoinMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/RejoinMessage.java index 256177d..6e98a65 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/RejoinMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/RejoinMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/PlayerData.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/PlayerData.java index 6f7387c..98147c7 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/PlayerData.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/PlayerData.java @@ -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 */ diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/SessionData.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/SessionData.java index 565b24d..d353427 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/SessionData.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/SessionData.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/CardMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/CardMessage.java index 984fe36..820999f 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/CardMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/CardMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/HandMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/HandMessage.java index b2ce3ed..146b857 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/HandMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/HandMessage.java @@ -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); } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/PredictionMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/PredictionMessage.java index 6dbcb65..71a0abd 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/PredictionMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/PredictionMessage.java @@ -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; + } } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/ScoreMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/ScoreMessage.java index a0ee775..0b75979 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/ScoreMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/ScoreMessage.java @@ -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); } } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/StateMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/StateMessage.java index 5973472..4f44c21 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/StateMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/StateMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/TrickMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/TrickMessage.java index b7b82cb..4f71e91 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/TrickMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/TrickMessage.java @@ -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 cards; + private final @Unmodifiable @NonNull List<@NonNull Card> cards; - public TrickMessage(UUID player, List cards) { + public TrickMessage(@NonNull UUID player, @NonNull List<@NonNull Card> cards) { this.player = player; this.cards = List.copyOf(cards); } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/UserInputMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/UserInputMessage.java index f34b3af..3dbbaee 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/UserInputMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/UserInputMessage.java @@ -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. */ diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/JuggleMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/JuggleMessage.java index 2d639fc..268fdf6 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/JuggleMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/JuggleMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PickTrumpMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PickTrumpMessage.java index be47021..3ecb708 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PickTrumpMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PickTrumpMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PlayCardMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PlayCardMessage.java index 6e33a03..8eaba56 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PlayCardMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PlayCardMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/GameMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/GameMessage.java index 37b3ed2..2a331dc 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/GameMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/GameMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickVotedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickVotedMessage.java index 0a5937b..0422d21 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickVotedMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickVotedMessage.java @@ -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} */ diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickedMessage.java index a7ce2d7..0d07df3 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickedMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickedMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/NackMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/NackMessage.java index ad17fc5..1e15b1d 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/NackMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/NackMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinedMessage.java index 8c0b2a1..3b0f75a 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinedMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinedMessage.java @@ -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); } } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeftMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeftMessage.java index cdde467..e23f553 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeftMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeftMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerModifiedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerModifiedMessage.java index 873cfa3..1014df2 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerModifiedMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerModifiedMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionCreatedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionCreatedMessage.java index 4e5c05f..46d9341 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionCreatedMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionCreatedMessage.java @@ -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); } } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionJoinedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionJoinedMessage.java index e43c74e..0bb311d 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionJoinedMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionJoinedMessage.java @@ -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 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 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); diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionListMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionListMessage.java index 5e76c81..6b26a90 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionListMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionListMessage.java @@ -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 sessions; + private final @Unmodifiable @NonNull List<@NonNull SessionData> sessions; - public SessionListMessage(List sessions) { + public SessionListMessage(@NonNull List<@NonNull SessionData> sessions) { this.sessions = List.copyOf(sessions); } } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionModifiedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionModifiedMessage.java index f03ec45..f7b279a 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionModifiedMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionModifiedMessage.java @@ -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; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionRemovedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionRemovedMessage.java index 5c939e5..4cb9548 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionRemovedMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionRemovedMessage.java @@ -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; }