From 6f39767fb48bb8ec359b45d44f33b28afcf01515 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 22 Apr 2024 00:37:49 -0400 Subject: [PATCH] Concurrency update --- src/engine/gameManager/ForgeManager.java | 2 +- src/engine/loot/WorkOrder.java | 4 ++-- src/engine/net/client/handlers/ItemProductionMsgHandler.java | 2 ++ src/engine/objects/NPC.java | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 25e13db0..7d2241b8 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/loot/WorkOrder.java b/src/engine/loot/WorkOrder.java index d5f5b2da..88c67c24 100644 --- a/src/engine/loot/WorkOrder.java +++ b/src/engine/loot/WorkOrder.java @@ -16,8 +16,8 @@ import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; -import java.util.ArrayList; import java.util.HashMap; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Delayed; import java.util.concurrent.TimeUnit; @@ -39,7 +39,7 @@ public class WorkOrder implements Delayed { public long completionTime; public boolean runCompleted = false; public boolean runCanceled = false; - public ArrayList cooking = new ArrayList<>(); + public CopyOnWriteArrayList cooking = new CopyOnWriteArrayList<>(); public WorkOrder() { diff --git a/src/engine/net/client/handlers/ItemProductionMsgHandler.java b/src/engine/net/client/handlers/ItemProductionMsgHandler.java index eb922feb..f165c447 100644 --- a/src/engine/net/client/handlers/ItemProductionMsgHandler.java +++ b/src/engine/net/client/handlers/ItemProductionMsgHandler.java @@ -164,6 +164,8 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { vendor.charItemManager.addItemToInventory(completedItem); + // Refresh the vendor inventory window + ItemProductionMsg outMsg1 = new ItemProductionMsg(vendor.building, vendor, completedItem, mbEnums.ProductionActionType.DEPOSIT, true); DispatchMessage.dispatchMsgToInterestArea(vendor, outMsg1, mbEnums.DispatchChannel.SECONDARY, 700, false, false); ItemProductionMsg outMsg2 = new ItemProductionMsg(vendor.building, vendor, completedItem, mbEnums.ProductionActionType.CONFIRM_DEPOSIT, true); diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index b567c200..1d463ae6 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -35,6 +35,7 @@ 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; @@ -872,7 +873,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 ArrayList<>()); + ForgeManager.vendorWorkOrderLookup.computeIfAbsent(this, k -> new CopyOnWriteArrayList<>()); this.symbol = this.contract.getIconID(); this.modTypeTable = this.contract.getNPCModTypeTable();