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