fixed npe in Session

main
Jonah Bauer 3 years ago
parent 33f1d7b839
commit 7b8c7249ea

@ -62,22 +62,23 @@ public final class Session extends BaseState {
var player = join.getPlayer(); var player = join.getPlayer();
log.info("Player {} joined the session.", player.getName()); log.info("Player {} joined the session.", player.getName());
players.put(player.getUuid(), player); players.put(player.getUuid(), player);
sessionScreen.addPlayer(player); if (sessionScreen != null) sessionScreen.addPlayer(player);
return Optional.empty(); return Optional.empty();
} else if (message instanceof PlayerLeftMessage leave) { } else if (message instanceof PlayerLeftMessage leave) {
var uuid = leave.getPlayer(); var uuid = leave.getPlayer();
var player = players.remove(uuid); var player = players.remove(uuid);
log.info("Player {} left the session.", player.getName()); log.info("Player {} left the session.", player.getName());
sessionScreen.removePlayer(uuid); if (sessionScreen != null) sessionScreen.removePlayer(uuid);
return Optional.empty(); return Optional.empty();
} else if (message instanceof PlayerModifiedMessage modified) { } else if (message instanceof PlayerModifiedMessage modified) {
var player = modified.getPlayer(); var player = modified.getPlayer();
log.info("Player {} was modified.", player.getName()); log.info("Player {} was modified.", player.getName());
players.put(player.getUuid(), player); players.put(player.getUuid(), player);
sessionScreen.modifyPlayer(player); if (sessionScreen != null) {
sessionScreen.modifyPlayer(player);
if (self.equals(player.getUuid())) { if (self.equals(player.getUuid())) {
sessionScreen.setReady(player.isReady()); sessionScreen.setReady(player.isReady());
}
} }
return Optional.empty(); return Optional.empty();
@ -89,11 +90,11 @@ public final class Session extends BaseState {
// TODO display error // TODO display error
log.error(nack.getMessage()); log.error(nack.getMessage());
sending = false; sending = false;
sessionScreen.setSending(false); if (sessionScreen != null) sessionScreen.setSending(false);
return Optional.empty(); return Optional.empty();
} else if (sending && message instanceof AckMessage) { } else if (sending && message instanceof AckMessage) {
sending = false; sending = false;
sessionScreen.setSending(false); if (sessionScreen != null) sessionScreen.setSending(false);
return Optional.empty(); return Optional.empty();
} else { } else {
return unexpectedMessage(client, message); return unexpectedMessage(client, message);
@ -105,7 +106,7 @@ public final class Session extends BaseState {
log.warn("Please slow down"); log.warn("Please slow down");
} else { } else {
sending = true; sending = true;
sessionScreen.setSending(true); if (sessionScreen != null) sessionScreen.setSending(true);
client.send(new ReadyMessage(ready)); client.send(new ReadyMessage(ready));
} }
return Optional.empty(); return Optional.empty();
@ -127,6 +128,7 @@ public final class Session extends BaseState {
sessionScreen.setReady(players.get(self).isReady()); sessionScreen.setReady(players.get(self).isReady());
sessionScreen.setPlayerName(getName()); sessionScreen.setPlayerName(getName());
sessionScreen.setSession(session, sessionName, configuration); sessionScreen.setSession(session, sessionName, configuration);
sessionScreen.setSending(sending);
return Optional.empty(); return Optional.empty();
} }

Loading…
Cancel
Save