fix: fixed null pointer exception at getting participant from null-valued EntityID
This commit is contained in:
parent
5e6745ee23
commit
6122c55025
@ -1,6 +1,7 @@
|
|||||||
package uulm.teamname.marvelous.server.lobby;
|
package uulm.teamname.marvelous.server.lobby;
|
||||||
|
|
||||||
import org.tinylog.Logger;
|
import org.tinylog.Logger;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
|
||||||
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
|
||||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||||
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||||
@ -159,7 +160,7 @@ public class Lobby {
|
|||||||
*/
|
*/
|
||||||
void updateTurnTimer() {
|
void updateTurnTimer() {
|
||||||
var currentlyActiveParticipant =
|
var currentlyActiveParticipant =
|
||||||
getParticipantForEntityType(game.state.getActiveCharacter().type);
|
getParticipantForEntityType(game.state.getActiveCharacter());
|
||||||
Logger.trace("Updating turnTimer...");
|
Logger.trace("Updating turnTimer...");
|
||||||
if (pauseSegment.isPaused()) {
|
if (pauseSegment.isPaused()) {
|
||||||
Logger.trace("Game is paused, clearing turnTimer");
|
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
|
* Returns an {@link Optional} of the {@link Participant} for the given {@link EntityType}, or an empty {@link
|
||||||
* Optional} if it was an NPC
|
* Optional} if it was an NPC
|
||||||
*/
|
*/
|
||||||
|
Optional<Participant> 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<Participant> getParticipantForEntityType(EntityType type) {
|
Optional<Participant> getParticipantForEntityType(EntityType type) {
|
||||||
if (type == EntityType.P1) {
|
if (type == EntityType.P1) {
|
||||||
return Optional.of(connection.getPlayer1());
|
return Optional.of(connection.getPlayer1());
|
||||||
} else if (type == EntityType.P2) {
|
} else if (type == EntityType.P2) {
|
||||||
Logger.trace("Scheduling turnTimer for Player2");
|
|
||||||
return Optional.of(connection.getPlayer2());
|
return Optional.of(connection.getPlayer2());
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
Loading…
Reference in New Issue
Block a user