diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-01-20 20:21:00 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-01-20 20:21:00 +0100 |
commit | 680b20370ad4563f202a08eae5713d0d1d7f9078 (patch) | |
tree | 49fad13bd420faa263e8dc28134468357a5cacca /src/main/java/at/hannibal2/skyhanni/features | |
parent | dd86bbaf6dd31b3b9c3340cf1ecf80eae1e94eff (diff) | |
download | skyhanni-680b20370ad4563f202a08eae5713d0d1d7f9078.tar.gz skyhanni-680b20370ad4563f202a08eae5713d0d1d7f9078.tar.bz2 skyhanni-680b20370ad4563f202a08eae5713d0d1d7f9078.zip |
creating and using TimeLimitedCache and TimeLimitedSet instead of guava cache.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
5 files changed, 17 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt index 4a41b332c..97945eb21 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt @@ -13,17 +13,15 @@ import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.exactLocation import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import com.google.common.cache.CacheBuilder +import at.hannibal2.skyhanni.utils.TimeLimitedCache import net.minecraft.entity.item.EntityItem import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.concurrent.TimeUnit +import kotlin.time.Duration.Companion.milliseconds class ShowFishingItemName { private val config get() = SkyHanniMod.feature.fishing.fishedItemName private var hasRodInHand = false - private var cache = - CacheBuilder.newBuilder().expireAfterWrite(750, TimeUnit.MILLISECONDS) - .build<EntityItem, Pair<LorenzVec, String>>() + private var cache = TimeLimitedCache<EntityItem, Pair<LorenzVec, String>>(750.milliseconds) // Taken from Skytils private val cheapCoins = setOf( @@ -77,7 +75,7 @@ class ShowFishingItemName { } } - for ((location, text) in cache.asMap().values) { + for ((location, text) in cache.values()) { event.drawString(location, text) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt index 86b0be8dd..b5684265f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt @@ -18,10 +18,10 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import com.google.common.cache.CacheBuilder +import at.hannibal2.skyhanni.utils.TimeLimitedCache import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.concurrent.TimeUnit import kotlin.random.Random +import kotlin.time.Duration.Companion.minutes object AdvancedPlayerList { private val config get() = SkyHanniMod.feature.misc.compactTabList.advancedPlayerList @@ -188,11 +188,10 @@ object AdvancedPlayerList { return "$level $playerName ${suffix.trim()}" } - private var randomOrderCache = - CacheBuilder.newBuilder().expireAfterWrite(20, TimeUnit.MINUTES).build<String, Int>() + private var randomOrderCache = TimeLimitedCache<String, Int>(20.minutes) private fun getRandomOrder(name: String): Int { - val saved = randomOrderCache.getIfPresent(name) + val saved = randomOrderCache.getOrNull(name) if (saved != null) { return saved } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt index 44c4f8cac..5f0ee6494 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt @@ -3,13 +3,12 @@ package at.hannibal2.skyhanni.features.misc.visualwords import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.convertToFormatted -import com.google.common.cache.Cache -import com.google.common.cache.CacheBuilder -import java.util.concurrent.TimeUnit +import at.hannibal2.skyhanni.utils.TimeLimitedCache +import kotlin.time.Duration.Companion.minutes object ModifyVisualWords { private val config get() = SkyHanniMod.feature.gui.modifyWords - var textCache: Cache<String, String> = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build() + var textCache = TimeLimitedCache<String, String>(5.minutes) var modifiedWords = mutableListOf<VisualWord>() @@ -23,7 +22,7 @@ object ModifyVisualWords { modifiedWords = SkyHanniMod.feature.storage.modifiedWords } - val cachedResult = textCache.getIfPresent(originalText) + val cachedResult = textCache.getOrNull(originalText) if (cachedResult != null) { return cachedResult } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt index 03cf21b1d..b88171e96 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt @@ -554,7 +554,7 @@ open class VisualWordGui : GuiScreen() { private fun saveChanges() { ModifyVisualWords.modifiedWords = modifiedWords - ModifyVisualWords.textCache.invalidateAll() + ModifyVisualWords.textCache.clear() SkyHanniMod.feature.storage.modifiedWords = modifiedWords } diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemsOnGround.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemsOnGround.kt index f0f80ace4..fedc9593a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemsOnGround.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemsOnGround.kt @@ -11,18 +11,16 @@ import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.exactLocation -import com.google.common.cache.CacheBuilder +import at.hannibal2.skyhanni.utils.TimeLimitedCache import net.minecraft.entity.item.EntityItem import net.minecraft.init.Items import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.concurrent.TimeUnit +import kotlin.time.Duration.Companion.seconds class SlayerItemsOnGround { private val config get() = SkyHanniMod.feature.slayer.itemsOnGround - private var itemsOnGround = - CacheBuilder.newBuilder().expireAfterWrite(2, TimeUnit.SECONDS) - .build<EntityItem, Pair<LorenzVec, String>>() + private var itemsOnGround = TimeLimitedCache<EntityItem, Pair<LorenzVec, String>>(2.seconds) @SubscribeEvent fun onRenderWorld(event: LorenzRenderWorldEvent) { @@ -47,7 +45,7 @@ class SlayerItemsOnGround { itemsOnGround.put(entityItem, location to itemName) } - for ((location, text) in itemsOnGround.asMap().values) { + for ((location, text) in itemsOnGround.values()) { event.drawString(location, text) } } |