Fixed: DisconnectedPlayer and ReconnectPlayer apply with minimodel not initialized, disconnection countdown when the game is ended. Fixed: the player is now removed from order if it was added before.

This commit is contained in:
rubenpirreram
2026-05-15 13:36:26 +02:00
parent 6ff79f2e1d
commit f3aaab516f
5 changed files with 19 additions and 11 deletions
@@ -4,6 +4,7 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* A {@link LinkedHashMap} with a configurable size limit and an associated action.
@@ -15,7 +16,7 @@ import java.util.Set;
*/
public class LimitedMap<K, V> implements Map<K, V> {
private final LinkedHashMap<K, V> map = new LinkedHashMap<>();
private final ConcurrentHashMap<K, V> map = new ConcurrentHashMap<>();
/**
* The maximum number of elements allowed in the map before the action is triggered.
@@ -70,7 +70,9 @@ public abstract class OrderLogicCard implements Serializable {
playerList=new ArrayList<>();
}
playerList.removeIf(x->player.getUserName().equals(x.player.getUserName()));
playerList.add(new OrderPlayer(player,false));
players.removeIf(x->player.getUserName().equals(x.getUserName()));
players.add(player);
}
@@ -35,10 +35,13 @@ public class DisconnectedPlayer extends NetworkEvent implements Serializable{
public boolean apply(MiniModel miniModel){
if(isError)
return false;
miniModel.setPlayer(player);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
if(miniModel!=null)
{
miniModel.setPlayer(player);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
}
return true;
}
@@ -33,10 +33,12 @@ public class ReconnectPlayer extends NetworkEvent implements Serializable{
public boolean apply(MiniModel miniModel){
if(isError)
return false;
miniModel.setPlayer(player);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
if(miniModel!=null) {
miniModel.setPlayer(player);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
}
return true;
}
@@ -156,7 +156,7 @@ public class ServerLauncher {
System.out.println("\n!!! Save failed !!!\n");
}
}
if (event.getEventType().equals(EventType.DISCONNECTED_PLAYER) && playerList.values().stream().filter(x -> x).count() == 1) {
if (event.getEventType().equals(EventType.DISCONNECTED_PLAYER) && playerList.values().stream().filter(x -> x).count() == 1&& game.getCurrentState().getGameStage() != GameStages.ENDED) {
if (disconnectionTimer != null && !disconnectionTimer.isDone()) {
disconnectionTimer.cancel(false);
}
@@ -277,7 +277,7 @@ public class ServerLauncher {
break;
}
catch(RemoteException e){
throw new RuntimeException(e);
//throw new RuntimeException(e);
}
}
}