forked from MagicBane/Server
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
10 months ago
|
package engine.util;
|
||
|
|
||
|
import engine.objects.PlayerCharacter;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.HashMap;
|
||
|
|
||
|
public class BoxTracker {
|
||
|
private static final HashMap<String, ArrayList<PlayerCharacter>> players_by_machine = new HashMap<>();
|
||
|
|
||
|
public static void addPlayer(String machineId, PlayerCharacter player) {
|
||
|
synchronized (players_by_machine) {
|
||
|
ArrayList<PlayerCharacter> 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<PlayerCharacter> 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<PlayerCharacter> players = players_by_machine.get(machineId);
|
||
|
if (players != null) {
|
||
|
players.remove(player);
|
||
|
if (players.isEmpty()) {
|
||
|
players_by_machine.remove(machineId);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|