From 2ea43c913a9d4d28e7d12918ac62c5ffde0ac311 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 28 Sep 2023 11:24:39 +0200 Subject: Ignoring non-slayer drops in slayer profit tracker. --- .../features/slayer/SlayerItemProfitTracker.kt | 20 ++++++++++++++++++++ .../java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 2 ++ .../jsonobjects/SlayerProfitTrackerItemsJson.java | 13 +++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/SlayerProfitTrackerItemsJson.java diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt index e93210b10..00b0f751d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.PurseChangeCause import at.hannibal2.skyhanni.events.PurseChangeEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.events.SlayerChangeEvent import at.hannibal2.skyhanni.events.SlayerQuestCompleteEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData @@ -20,6 +21,7 @@ import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector +import at.hannibal2.skyhanni.utils.LorenzUtils.get import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems.getNpcPrice @@ -29,6 +31,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.jsonobjects.SlayerProfitTrackerItemsJson import at.hannibal2.skyhanni.utils.renderables.Renderable import com.google.common.cache.CacheBuilder import net.minecraft.client.Minecraft @@ -60,6 +63,14 @@ object SlayerItemProfitTracker { update() } + private var allowedItems = mapOf>() + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + val items = event.getConstant("SlayerProfitTrackerItems") ?: return + allowedItems = items.slayers + } + @SubscribeEvent fun onPurseChange(event: PurseChangeEvent) { if (!isEnabled()) return @@ -147,6 +158,10 @@ object SlayerItemProfitTracker { val name = itemStack.name ?: return if (SlayerAPI.ignoreSlayerDrop(name)) return val internalName = itemStack.getInternalNameOrNull() ?: return + if (!isAllowedItem(internalName)) { + LorenzUtils.debug("Ignored non-slayer item pickup: '$internalName' '$itemLogCategory'") + return + } val (itemName, price) = SlayerAPI.getItemNameAndPrice(itemStack) addItemPickup(internalName, itemStack.stackSize) @@ -163,6 +178,11 @@ object SlayerItemProfitTracker { } } + private fun isAllowedItem(internalName: NEUInternalName): Boolean { + val allowedList = allowedItems.get { itemLogCategory.startsWith(it) } ?: return false + return internalName in allowedList + } + fun update() { display = drawDisplay() } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 3ad8e3fe9..5275b9196 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -540,4 +540,6 @@ object LorenzUtils { fun T.conditionalTransform(condition: Boolean, ifTrue: T.() -> Any, ifFalse: T.() -> Any) = if (condition) ifTrue(this) else ifFalse(this) + + fun Map.get(function: (K) -> Boolean) = entries.firstOrNull { function(it.key) }?.value } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/SlayerProfitTrackerItemsJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/SlayerProfitTrackerItemsJson.java new file mode 100644 index 000000000..4c06aeb55 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/SlayerProfitTrackerItemsJson.java @@ -0,0 +1,13 @@ +package at.hannibal2.skyhanni.utils.jsonobjects; + +import at.hannibal2.skyhanni.utils.NEUInternalName; +import com.google.gson.annotations.Expose; + +import java.util.List; +import java.util.Map; + +public class SlayerProfitTrackerItemsJson { + + @Expose + public Map> slayers; +} -- cgit