diff options
author | Empa <42304516+ItsEmpa@users.noreply.github.com> | 2024-05-24 14:36:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-24 14:36:56 +0200 |
commit | fe0449b9b8161135874ac99c1685233349f06f0d (patch) | |
tree | c14bd993d1dab1cc771b13fa4cb99c7a7f3a1864 /src/main/java/at/hannibal2/skyhanni/data | |
parent | cb6869cb79cb4f5679eb90f9120c716b77a9078e (diff) | |
download | skyhanni-fe0449b9b8161135874ac99c1685233349f06f0d.tar.gz skyhanni-fe0449b9b8161135874ac99c1685233349f06f0d.tar.bz2 skyhanni-fe0449b9b8161135874ac99c1685233349f06f0d.zip |
Backend: GetOrPut in TimeLimitedCache (#1875)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt index ec62adda0..f4235cb73 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt @@ -38,27 +38,21 @@ object SlayerAPI { System.currentTimeMillis() } else latestProgressChangeTime - fun getItemNameAndPrice(internalName: NEUInternalName, amount: Int): Pair<String, Double> { - val key = internalName to amount - nameCache.getOrNull(key)?.let { - return it - } - - val amountFormat = if (amount != 1) "§7${amount}x §r" else "" - val displayName = internalName.itemName + fun getItemNameAndPrice(internalName: NEUInternalName, amount: Int): Pair<String, Double> = + nameCache.getOrPut(internalName to amount) { + val amountFormat = if (amount != 1) "§7${amount}x §r" else "" + val displayName = internalName.itemName - val price = internalName.getPrice() - val npcPrice = internalName.getNpcPriceOrNull() ?: 0.0 - val maxPrice = npcPrice.coerceAtLeast(price) - val totalPrice = maxPrice * amount + val price = internalName.getPrice() + val npcPrice = internalName.getNpcPriceOrNull() ?: 0.0 + val maxPrice = npcPrice.coerceAtLeast(price) + val totalPrice = maxPrice * amount - val format = NumberUtil.format(totalPrice) - val priceFormat = " §7(§6$format coins§7)" + val format = NumberUtil.format(totalPrice) + val priceFormat = " §7(§6$format coins§7)" - val result = "$amountFormat$displayName$priceFormat" to totalPrice - nameCache.put(key, result) - return result - } + "$amountFormat$displayName$priceFormat" to totalPrice + } @SubscribeEvent fun onDebugDataCollect(event: DebugDataCollectEvent) { |