From 0e7336b8c6c104dd602584d2f1469d7b5a6b8d47 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 22 Apr 2024 07:35:59 -0400 Subject: [PATCH] Concurrency update --- src/engine/gameManager/ForgeManager.java | 2 +- src/engine/gameManager/NPCManager.java | 4 ++-- src/engine/objects/NPC.java | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 7d2241b8..e35d4007 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -29,7 +29,7 @@ public enum ForgeManager implements Runnable { private static final BlockingQueue forge = new DelayQueue<>(); public static final AtomicInteger wordOrderCounter = new AtomicInteger(0); - public static final ConcurrentHashMap> vendorWorkOrderLookup = new ConcurrentHashMap<>(); + public static final ConcurrentHashMap> vendorWorkOrderLookup = new ConcurrentHashMap<>(); public static final ConcurrentHashMap itemWorkOrderLookup = new ConcurrentHashMap<>(); @Override diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index 7e5acf18..59e348e0 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -27,7 +27,7 @@ import org.pmw.tinylog.Logger; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; import static engine.math.FastMath.acos; @@ -523,7 +523,7 @@ public enum NPCManager { ArrayList itemList = new ArrayList<>(); - List vendorWorkOrders = ForgeManager.vendorWorkOrderLookup.get(npc); + ConcurrentHashMap.KeySetView vendorWorkOrders = ForgeManager.vendorWorkOrderLookup.get(npc); for (WorkOrder workOrder : vendorWorkOrders) itemList.addAll(workOrder.cooking); diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index 1d463ae6..ddb12851 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -35,7 +35,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.ReentrantReadWriteLock; import static engine.net.client.msg.ErrorPopupMsg.sendErrorPopup; @@ -873,7 +872,7 @@ public class NPC extends AbstractCharacter { // If NPC is a vendor then configure ForgeManager support if (this.contract.isTrainer() == false) - ForgeManager.vendorWorkOrderLookup.computeIfAbsent(this, k -> new CopyOnWriteArrayList<>()); + ForgeManager.vendorWorkOrderLookup.computeIfAbsent(this, k -> ConcurrentHashMap.newKeySet()); this.symbol = this.contract.getIconID(); this.modTypeTable = this.contract.getNPCModTypeTable();