Skip to content

Commit

Permalink
Fix: Widget Update (#2923)
Browse files Browse the repository at this point in the history
Co-authored-by: Empa <itsempa@users.noreply.github.com>
  • Loading branch information
ItsEmpa and ItsEmpa authored Nov 15, 2024
1 parent a20c43d commit 295cb9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ object ProfileStorageData {
noTabListTime = SimpleTimeMark.now()
val foundSkyBlockTabList = TabListData.getTabList().any { it.contains("§b§lArea:") }
if (foundSkyBlockTabList) {
println("Tablist missing debug:\n${TabListData.getTabList()}")
ChatUtils.clickableChat(
"§cCan not read profile name from tab list! Open /widget and enable Profile Widget. " +
"This is needed for the mod to function! And therefore this warning cannot be disabled",
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package at.hannibal2.skyhanni.data.model

import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.events.WidgetUpdateEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy
import at.hannibal2.skyhanni.utils.CollectionUtils.getOrNull
import at.hannibal2.skyhanni.utils.ConditionalUtils.transformIf
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Matcher
import java.util.regex.Pattern
import kotlin.time.Duration.Companion.seconds

private val repoGroup by RepoPattern.exclusiveGroup("tab.widget.enum")

Expand Down Expand Up @@ -371,10 +376,24 @@ enum class TabWidget(
/** Patterns that where loaded from a future version*/
private var extraPatterns: List<Pattern> = emptyList()

private var sentSinceWorldChange = false

init {
entries.forEach { it.pattern }
}

private val FORCE_UPDATE_DELAY = 2.seconds

@SubscribeEvent
fun onSecond(event: SecondPassedEvent) {
if (sentSinceWorldChange || !LorenzUtils.inSkyBlock) return
if (LorenzUtils.lastWorldSwitch.passedSince() < FORCE_UPDATE_DELAY) return
sentSinceWorldChange = true
@Suppress("DEPRECATION")
update(TabListData.getTabList())
ChatUtils.debug("Forcefully Updated Widgets")
}

@SubscribeEvent(priority = EventPriority.HIGH)
fun onTabListUpdate(event: TabListUpdateEvent) {
if (!LorenzUtils.inSkyBlock) {
Expand All @@ -384,8 +403,11 @@ enum class TabWidget(
}
return
}
update(event.tabList)
}

val tabList = filterTabList(event.tabList)
private fun update(newTablist: List<String>) {
val tabList = filterTabList(newTablist)

separatorIndexes.clear()

Expand All @@ -409,6 +431,11 @@ enum class TabWidget(
}
}

@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
sentSinceWorldChange = false
}

@SubscribeEvent(priority = EventPriority.LOW)
fun onRepoReload(event: RepositoryReloadEvent) {
extraPatterns = repoGroup.getUnusedPatterns()
Expand Down

0 comments on commit 295cb9d

Please sign in to comment.