Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Widget Update #2923

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading