From 6122c55025fea8d626c8b7e98b32f1d3356d3ae5 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Mon, 7 Jun 2021 17:10:30 +0200 Subject: [PATCH] fix: fixed null pointer exception at getting participant from null-valued EntityID --- .../uulm/teamname/marvelous/server/lobby/Lobby.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java index 551b25a..1440d34 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java @@ -1,6 +1,7 @@ package uulm.teamname.marvelous.server.lobby; import org.tinylog.Logger; +import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.EntityType; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.EventBuilder; @@ -159,7 +160,7 @@ public class Lobby { */ void updateTurnTimer() { var currentlyActiveParticipant = - getParticipantForEntityType(game.state.getActiveCharacter().type); + getParticipantForEntityType(game.state.getActiveCharacter()); Logger.trace("Updating turnTimer..."); if (pauseSegment.isPaused()) { Logger.trace("Game is paused, clearing turnTimer"); @@ -180,11 +181,19 @@ public class Lobby { * Returns an {@link Optional} of the {@link Participant} for the given {@link EntityType}, or an empty {@link * Optional} if it was an NPC */ + Optional getParticipantForEntityType(EntityID entityID) { + if (entityID == null) { + Logger.trace("cannot get participant for empty EntityType, returning empty Optional"); + return Optional.empty(); + } else { + return getParticipantForEntityType(entityID.type); + } + } + Optional getParticipantForEntityType(EntityType type) { if (type == EntityType.P1) { return Optional.of(connection.getPlayer1()); } else if (type == EntityType.P2) { - Logger.trace("Scheduling turnTimer for Player2"); return Optional.of(connection.getPlayer2()); } else { return Optional.empty();