From 5da1b85f28912d2134d62012b6920b4f197100bc Mon Sep 17 00:00:00 2001 From: iProdigy <8106344+iProdigy@users.noreply.github.com> Date: Sat, 12 Oct 2024 12:53:01 -0500 Subject: [PATCH] perf(loot): skip allow list regex if item on deny list (#565) --- CHANGELOG.md | 1 + src/main/java/dinkplugin/notifiers/LootNotifier.java | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4356384..39f57e78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased - Bugfix: Enforce value threshold for always-dropped loot when rarity threshold is 1 and require both value and rarity is true. (#560) +- Dev: Optimize regex performance for looted items on the item denylist. (#565) ## 1.10.11 diff --git a/src/main/java/dinkplugin/notifiers/LootNotifier.java b/src/main/java/dinkplugin/notifiers/LootNotifier.java index fc4b9186..db87142e 100644 --- a/src/main/java/dinkplugin/notifiers/LootNotifier.java +++ b/src/main/java/dinkplugin/notifiers/LootNotifier.java @@ -173,13 +173,14 @@ private void handleNotify(Collection items, String dropper, LootRecor shouldSend = totalPrice >= minValue || MathUtils.lessThanOrEqual(rarity.orElse(1), rarityThreshold); } - shouldSend |= matches(itemNameAllowlist, stack.getName()); - boolean denied = matches(itemNameDenylist, stack.getName()); if (denied) { shouldSend = false; - } else if (max == null || totalPrice > max.getTotalPrice()) { - max = stack; + } else { + shouldSend |= matches(itemNameAllowlist, stack.getName()); + if (max == null || totalPrice > max.getTotalPrice()) { + max = stack; + } } if (shouldSend) { @@ -218,7 +219,7 @@ private void handleNotify(Collection items, String dropper, LootRecor } if (sendMessage) { - if (npcId == null && (type == LootRecordType.NPC || type == LootRecordType.PICKPOCKET)) { + if (npcId == null && (type == LootRecordType.NPC || type == LootRecordType.PICKPOCKET)) { npcId = client.getTopLevelWorldView().npcs().stream() .filter(npc -> dropper.equals(npc.getName())) .findAny()