Skip to content

Commit

Permalink
Backend: Widget abstractions (#1150)
Browse files Browse the repository at this point in the history
Co-authored-by: Cal <cwolfson58@gmail.com>
  • Loading branch information
Thunderblade73 and CalMWolfs authored Jun 3, 2024
1 parent 960009e commit 0d28849
Show file tree
Hide file tree
Showing 5 changed files with 503 additions and 47 deletions.
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import at.hannibal2.skyhanni.data.jsonobjects.local.VisualWordsJson
import at.hannibal2.skyhanni.data.mob.MobData
import at.hannibal2.skyhanni.data.mob.MobDebug
import at.hannibal2.skyhanni.data.mob.MobDetection
import at.hannibal2.skyhanni.data.model.TabWidget
import at.hannibal2.skyhanni.data.repo.RepoManager
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.PreInitFinishedEvent
Expand Down Expand Up @@ -577,6 +578,7 @@ class SkyHanniMod {
loadModule(ChatUtils)
loadModule(FixedRateTimerManager())
loadModule(ChromaManager)
loadModule(TabWidget)
loadModule(HotmData)
loadModule(ContributorManager)
loadModule(TabComplete)
Expand Down
90 changes: 44 additions & 46 deletions src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigManager.Companion.gson
import at.hannibal2.skyhanni.data.model.TabWidget
import at.hannibal2.skyhanni.events.HypixelJoinEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.events.WidgetUpdateEvent
import at.hannibal2.skyhanni.features.bingo.BingoAPI
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.features.rift.RiftAPI
Expand Down Expand Up @@ -36,69 +38,57 @@ class HypixelData {

private val patternGroup = RepoPattern.group("data.hypixeldata")
private val islandNamePattern by patternGroup.pattern(
"islandname",
"(?:§.)*(Area|Dungeon): (?:§.)*(?<island>.*)"
"islandname", "(?:§.)*(Area|Dungeon): (?:§.)*(?<island>.*)"
)

private var lastLocRaw = SimpleTimeMark.farPast()

companion object {
private val patternGroup = RepoPattern.group("data.hypixeldata")
private val serverIdScoreboardPattern by patternGroup.pattern(
"serverid.scoreboard",
"§7\\d+/\\d+/\\d+ §8(?<servertype>[mM])(?<serverid>\\S+).*"
"serverid.scoreboard", "§7\\d+/\\d+/\\d+ §8(?<servertype>[mM])(?<serverid>\\S+).*"
)
private val serverIdTablistPattern by patternGroup.pattern(
"serverid.tablist",
" Server: §r§8(?<serverid>\\S+)"
"serverid.tablist", " Server: §r§8(?<serverid>\\S+)"
)
private val lobbyTypePattern by patternGroup.pattern(
"lobbytype",
"(?<lobbyType>.*lobby)\\d+"
"lobbytype", "(?<lobbyType>.*lobby)\\d+"
)
private val playerAmountPattern by patternGroup.pattern(
"playeramount",
"^\\s*(?:§.)+Players (?:§.)+\\((?<amount>\\d+)\\)\\s*$"
"playeramount", "^\\s*(?:§.)+Players (?:§.)+\\((?<amount>\\d+)\\)\\s*$"
)
private val playerAmountCoopPattern by patternGroup.pattern(
"playeramount.coop",
"^\\s*(?:§.)*Coop (?:§.)*\\((?<amount>\\d+)\\)\\s*$"
"playeramount.coop", "^\\s*(?:§.)*Coop (?:§.)*\\((?<amount>\\d+)\\)\\s*$"
)
private val playerAmountGuestingPattern by patternGroup.pattern(
"playeramount.guesting",
"^\\s*(?:§.)*Guests (?:§.)*\\((?<amount>\\d+)\\)\\s*$"
"playeramount.guesting", "^\\s*(?:§.)*Guests (?:§.)*\\((?<amount>\\d+)\\)\\s*$"
)

/**
* REGEX-TEST: §r§b§lParty §r§f(4)
*/
private val dungeonPartyAmountPattern by patternGroup.pattern(
"playeramount.dungeonparty",
"^\\s*(?:§.)+Party (?:§.)+\\((?<amount>\\d+)\\)\\s*$"
"playeramount.dungeonparty", "^\\s*(?:§.)+Party (?:§.)+\\((?<amount>\\d+)\\)\\s*$"
)
private val soloProfileAmountPattern by patternGroup.pattern(
"solo.profile.amount",
"^\\s*(?:§.)*Island\\s*$"
"solo.profile.amount", "^\\s*(?:§.)*Island\\s*$"
)
private val scoreboardVisitingAmoutPattern by patternGroup.pattern(
"scoreboard.visiting.amount",
"\\s+§.✌ §.\\(§.(?<currentamount>\\d+)§./(?<maxamount>\\d+)\\)"
"scoreboard.visiting.amount", "\\s+§.✌ §.\\(§.(?<currentamount>\\d+)§./(?<maxamount>\\d+)\\)"
)
private val guestPattern by patternGroup.pattern(
"guesting.scoreboard",
"SKYBLOCK GUEST"
"guesting.scoreboard", "SKYBLOCK GUEST"
)
private val scoreboardTitlePattern by patternGroup.pattern(
"scoreboard.title",
"SK[YI]BLOCK(?: CO-OP| GUEST)?"
"scoreboard.title", "SK[YI]BLOCK(?: CO-OP| GUEST)?"
)

/**
* REGEX-TEST: §7⏣ §bVillage
* REGEX-TEST: §5ф §dWizard Tower
*/
private val skyblockAreaPattern by patternGroup.pattern(
"skyblock.area",
"\\s*§(?<symbol>7⏣|5ф) §(?<color>.)(?<area>.*)"
"skyblock.area", "\\s*§(?<symbol>7⏣|5ф) §(?<color>.)(?<area>.*)"
)

var hypixelLive = false
Expand All @@ -125,12 +115,7 @@ class HypixelData {
// Data from locraw
var locrawData: JsonObject? = null
private var locraw: MutableMap<String, String> = mutableMapOf(
"server" to "",
"gametype" to "",
"lobbyname" to "",
"lobbytype" to "",
"mode" to "",
"map" to ""
"server" to "", "gametype" to "", "lobbyname" to "", "lobbytype" to "", "mode" to "", "map" to ""
)

val server get() = locraw["server"] ?: ""
Expand Down Expand Up @@ -158,7 +143,8 @@ class HypixelData {
}

ErrorManager.logErrorWithData(
Exception("NoServerId"), "Could not find server id",
Exception("NoServerId"),
"Could not find server id",
"islandType" to LorenzUtils.skyBlockIsland,
"tablist" to TabListData.getTabList(),
"scoreboard" to ScoreboardData.sidebarLinesFormatted
Expand Down Expand Up @@ -302,10 +288,7 @@ class HypixelData {
// So, as requested by Hannibal, use locraw from
// NEU and have NEU send it.
// Remove this when NEU dependency is removed
if (LorenzUtils.onHypixel &&
locrawData == null &&
lastLocRaw.passedSince() > 15.seconds
) {
if (LorenzUtils.onHypixel && locrawData == null && lastLocRaw.passedSince() > 15.seconds) {
lastLocRaw = SimpleTimeMark.now()
thread(start = true) {
Thread.sleep(1000)
Expand Down Expand Up @@ -342,7 +325,6 @@ class HypixelData {

val inSkyBlock = checkScoreboard()
if (inSkyBlock) {
checkIsland()
checkSidebar()
checkCurrentServerId()
}
Expand All @@ -351,6 +333,14 @@ class HypixelData {
skyBlock = inSkyBlock
}

@SubscribeEvent
fun onTabListUpdate(event: WidgetUpdateEvent) {
when (event.widget) {
TabWidget.AREA -> checkIsland(event)
else -> Unit
}
}

private fun checkProfileName() {
if (profileName.isNotEmpty()) return

Expand Down Expand Up @@ -392,18 +382,23 @@ class HypixelData {
noTrade = ironman || stranded || bingo
}

private fun checkIsland() {
var foundIsland = ""
TabListData.fullyLoaded = false
private fun checkIsland(event: WidgetUpdateEvent) {
val islandType: IslandType
val foundIsland: String
if (event.isClear()) {

TabListData.fullyLoaded = false
islandType = IslandType.NONE
foundIsland = ""

TabListData.getTabList().matchFirst(islandNamePattern) {
foundIsland = group("island").removeColor()
} else {
TabListData.fullyLoaded = true
// Can not use color coding, because of the color effect (§f§lSKYB§6§lL§e§lOCK§A§L GUEST)
val guesting = guestPattern.matches(ScoreboardData.objectiveTitle.removeColor())
foundIsland = TabWidget.AREA.matchMatcherFirstLine { group("island").removeColor() } ?: ""
islandType = getIslandType(foundIsland, guesting)
}

// Can not use color coding, because of the color effect (§f§lSKYB§6§lL§e§lOCK§A§L GUEST)
val guesting = guestPattern.matches(ScoreboardData.objectiveTitle.removeColor())
val islandType = getIslandType(foundIsland, guesting)
if (skyBlockIsland != islandType) {
IslandChangeEvent(islandType, skyBlockIsland).postAndCatch()
if (islandType == IslandType.UNKNOWN) {
Expand All @@ -413,6 +408,9 @@ class HypixelData {
loggerIslandChange.log(islandType.name)
}
skyBlockIsland = islandType
if (TabListData.fullyLoaded) {
TabWidget.reSendEvents()
}
}
}

Expand Down
Loading

0 comments on commit 0d28849

Please sign in to comment.