package engine.util; import engine.objects.PlayerCharacter; import java.util.ArrayList; import java.util.HashMap; public class BoxTracker { private static final HashMap> players_by_machine = new HashMap<>(); public static void addPlayer(String machineId, PlayerCharacter player) { synchronized (players_by_machine) { ArrayList players = players_by_machine.get(machineId); if (players != null) { player.isBoxed = true; players.add(player); } else { players = new ArrayList<>(); players.add(player); players_by_machine.put(machineId, players); } } } public static ArrayList getPlayers(String machineId) { synchronized (players_by_machine) { return new ArrayList<>(players_by_machine.getOrDefault(machineId, new ArrayList<>())); } } public static void removePlayer(String machineId, PlayerCharacter player) { synchronized (players_by_machine) { ArrayList players = players_by_machine.get(machineId); if (players != null) { players.remove(player); if (players.isEmpty()) { players_by_machine.remove(machineId); } } } } }