aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt4
2 files changed, 8 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
index 7519662a7..765a51e95 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
@@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isRancherSign
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.ReflectionUtils.getPropertiesWithType
import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.TimeLimitedCache
import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer
import net.minecraft.client.Minecraft
@@ -26,6 +27,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.UUID
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
+import kotlin.time.Duration.Companion.seconds
class GuiEditManager {
@@ -50,8 +52,6 @@ class GuiEditManager {
@SubscribeEvent(priority = EventPriority.LOWEST)
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
- latestPositions = currentPositions.toMap()
- currentPositions.clear()
GlStateManager.color(1f, 1f, 1f, 1f)
GlStateManager.enableBlend()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
@@ -67,8 +67,7 @@ class GuiEditManager {
companion object {
- var currentPositions = mutableMapOf<String, Position>()
- private var latestPositions = mapOf<String, Position>()
+ private var currentPositions = TimeLimitedCache<String, Position>(15.seconds)
private var currentBorderSize = mutableMapOf<String, Pair<Int, Int>>()
private var lastMovedGui: String? = null
@@ -79,10 +78,8 @@ class GuiEditManager {
name = if (posLabel == "none") "none " + UUID.randomUUID() else posLabel
position.internalName = name
}
- if (!currentPositions.containsKey(name)) {
- currentPositions[name] = position
- currentBorderSize[posLabel] = Pair(x, y)
- }
+ currentPositions.put(name, position)
+ currentBorderSize[posLabel] = Pair(x, y)
}
private var lastHotkeyReminded = SimpleTimeMark.farPast()
@@ -90,7 +87,7 @@ class GuiEditManager {
@JvmStatic
fun openGuiPositionEditor(hotkeyReminder: Boolean) {
SkyHanniMod.screenToOpen = GuiPositionEditor(
- latestPositions.values.toList(),
+ currentPositions.values().toList(),
2,
Minecraft.getMinecraft().currentScreen as? GuiContainer
)
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt
index 9f29b9ff1..d903ada07 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt
@@ -15,9 +15,9 @@ class TimeLimitedCache<K, V>(expireAfterWrite: Duration) {
fun clear() = cache.invalidateAll()
- fun values(): MutableCollection<V> = cache.asMap().values
+ fun values(): Collection<V> = cache.asMap().values
- fun keys(): MutableSet<K> = cache.asMap().keys
+ fun keys(): Set<K> = cache.asMap().keys
fun containsKey(key: K): Boolean = cache.getIfPresent(key) != null
}