From 0e23ddc3437f41ec14c4a611ce927d34b8405cac Mon Sep 17 00:00:00 2001 From: Johannes Hochwart Date: Wed, 10 Nov 2021 20:27:19 +0100 Subject: [PATCH] Bugfixes --- .../wizard/common/messages/observer/HandMessage.java | 4 ++-- ...layerJoinMessage.java => PlayerJoinedMessage.java} | 4 ++-- ...PlayerLeaveMessage.java => PlayerLeftMessage.java} | 2 +- .../common/messages/server/PlayerModifiedMessage.java | 4 ++-- .../wizard/common/messages/server/ServerMessage.java | 2 +- .../core/machine/states/round/DeterminingTrump.java | 11 +++++++++-- .../wizard/core/machine/states/trick/PlayingCard.java | 3 +++ .../jonahbauer/wizard/core/model/card/CardUtils.java | 2 +- 8 files changed, 21 insertions(+), 11 deletions(-) rename wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/{PlayerJoinMessage.java => PlayerJoinedMessage.java} (63%) rename wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/{PlayerLeaveMessage.java => PlayerLeftMessage.java} (84%) 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 33b768c..b2ce3ed 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 @@ -19,8 +19,8 @@ public final class HandMessage extends ObserverMessage { */ private final @NotNull UUID player; /** - * A list of all the hand cards. May consist only of {@link Card#HIDDEN} if the cars are not visible to the player - * receiving this message + * 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; diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinedMessage.java similarity index 63% rename from wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinMessage.java rename to wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinedMessage.java index 00aa869..8c0b2a1 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinedMessage.java @@ -4,9 +4,9 @@ import eu.jonahbauer.wizard.common.messages.data.PlayerData; import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) -public final class PlayerJoinMessage extends PlayerModifiedMessage { +public final class PlayerJoinedMessage extends PlayerModifiedMessage { - public PlayerJoinMessage(PlayerData playerData) { + public PlayerJoinedMessage(PlayerData playerData) { super(playerData); } } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeaveMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeftMessage.java similarity index 84% rename from wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeaveMessage.java rename to wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeftMessage.java index ff18a82..cdde467 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeaveMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeftMessage.java @@ -9,7 +9,7 @@ import java.util.UUID; @Getter @RequiredArgsConstructor @EqualsAndHashCode(callSuper = true) -public final class PlayerLeaveMessage extends ServerMessage { +public final class PlayerLeftMessage extends ServerMessage { /** * UUID of player who has left */ 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 a8e547c..873cfa3 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 @@ -8,9 +8,9 @@ import lombok.RequiredArgsConstructor; @Getter @RequiredArgsConstructor @EqualsAndHashCode(callSuper = true) -public sealed class PlayerModifiedMessage extends ServerMessage permits PlayerJoinMessage { +public sealed class PlayerModifiedMessage extends ServerMessage permits PlayerJoinedMessage { /** * Joining player */ - private final PlayerData playerData; + private final PlayerData player; } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java index 392e099..62e90ea 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java @@ -7,7 +7,7 @@ import eu.jonahbauer.wizard.common.util.SealedClassTypeAdapterFactory; import lombok.EqualsAndHashCode; @EqualsAndHashCode -public abstract sealed class ServerMessage permits AckMessage, GameMessage, JoinedSessionMessage, NackMessage, PlayerLeaveMessage, PlayerModifiedMessage, SessionListMessage, SessionModifiedMessage, SessionRemovedMessage, StartingGameMessage { +public abstract sealed class ServerMessage permits AckMessage, GameMessage, JoinedSessionMessage, NackMessage, PlayerLeftMessage, PlayerModifiedMessage, SessionListMessage, SessionModifiedMessage, SessionRemovedMessage, StartingGameMessage { public static final Gson GSON = new GsonBuilder() .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ServerMessage.class, "Message")) .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message")) diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrump.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrump.java index 0db0196..20490fb 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrump.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrump.java @@ -57,7 +57,12 @@ public final class DeterminingTrump extends RoundState { @Override public void onTimeout(Game game) { - Card.Suit[] suits = new Card.Suit[]{Card.Suit.BLUE, Card.Suit.GREEN, Card.Suit.RED, Card.Suit.YELLOW}; + Card.Suit[] suits; + if (werewolf) { + suits = new Card.Suit[]{Card.Suit.BLUE, Card.Suit.GREEN, Card.Suit.RED, Card.Suit.YELLOW, Card.Suit.NONE}; + } else { + suits = new Card.Suit[]{Card.Suit.BLUE, Card.Suit.GREEN, Card.Suit.RED, Card.Suit.YELLOW}; + } transition(game, suits[game.getRandom().nextInt(suits.length)]); } @@ -72,8 +77,10 @@ public final class DeterminingTrump extends RoundState { } private void checkTrumpSuit(Card.Suit suit) { - if (suit == Card.Suit.NONE) { + if (!werewolf && suit == Card.Suit.NONE) { throw new IllegalArgumentException("Trump suit must not be " + Card.Suit.NONE + "."); + } else if (suit == null) { + throw new IllegalArgumentException("Trump suit must not be null."); } } diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/PlayingCard.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/PlayingCard.java index 04a956c..3a94213 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/PlayingCard.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/PlayingCard.java @@ -33,6 +33,9 @@ public final class PlayingCard extends TrickState { @Override public void onMessage(Game game, UUID player, PlayerMessage message) { if (get(CURRENT_PLAYER).equals(player) && message instanceof PlayCardMessage cardMessage) { + if (cardMessage.getCard() == null) { + throw new IllegalArgumentException("Card must not be null."); + } transition(game, cardMessage.getCard()); } else { super.onMessage(game, player, message); diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/CardUtils.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/CardUtils.java index 674e4fd..b08db63 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/CardUtils.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/CardUtils.java @@ -57,7 +57,7 @@ public class CardUtils { } else if (card instanceof ColoredCard coloredCard) { if (coloredCard.getSuit() == trumpSuit) { return 200 + coloredCard.getValue(); - } else if (coloredCard.getSuit() == suit) { + } else if (coloredCard.getSuit() == suit) { return 100 + coloredCard.getValue(); } else { return coloredCard.getValue();