From 83499816eb3458478464a3bad6206ffd694f37b2 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 29 May 2024 19:25:45 -0500 Subject: [PATCH] Box Tracker --- .../InterestManagement/InterestManager.java | 3 +- src/engine/util/BoxTracker.java | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/engine/util/BoxTracker.java diff --git a/src/engine/InterestManagement/InterestManager.java b/src/engine/InterestManagement/InterestManager.java index 1ddd721a..87ad432f 100644 --- a/src/engine/InterestManagement/InterestManager.java +++ b/src/engine/InterestManagement/InterestManager.java @@ -25,6 +25,7 @@ import engine.net.client.msg.MoveToPointMsg; import engine.net.client.msg.UnloadObjectsMsg; import engine.objects.*; import engine.server.MBServerStatics; +import engine.util.BoxTracker; import org.pmw.tinylog.Logger; import java.util.ArrayList; @@ -524,7 +525,7 @@ public enum InterestManager implements Runnable { player.setDirtyLoad(true); updateStaticList(player, origin); updateMobileList(player, origin); - //PlayerCharacter.checkIfBoxed(player); + BoxTracker.addPlayer(origin.machineID,player); } diff --git a/src/engine/util/BoxTracker.java b/src/engine/util/BoxTracker.java new file mode 100644 index 00000000..1ed1d5b1 --- /dev/null +++ b/src/engine/util/BoxTracker.java @@ -0,0 +1,43 @@ +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); + } + } + } + } + +}