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: Custom Scoreboard Player Count Including Offline Players #3026

Merged
merged 11 commits into from
Dec 13, 2024
35 changes: 20 additions & 15 deletions src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.inAnyIsland
import at.hannibal2.skyhanni.utils.RegexUtils.allMatches
import at.hannibal2.skyhanni.utils.RegexUtils.firstMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
Expand Down Expand Up @@ -89,11 +91,11 @@ object HypixelData {
)

/**
* REGEX-TEST: §r§b§lCoop §r§f(4)
* REGEX-TEST: §8[§r§a§r§8] §r§bBpoth §r§6§l℻
*/
private val playerAmountCoopPattern by patternGroup.pattern(
private val playerAmountOnIslandPattern by patternGroup.pattern(
"playeramount.coop",
"^\\s*(?:§.)*Coop (?:§.)*\\((?<amount>\\d+)\\)\\s*$",
"^§.\\[[§\\w]{6,11}] §r.*",
CalMWolfs marked this conversation as resolved.
Show resolved Hide resolved
)

/**
Expand All @@ -112,14 +114,6 @@ object HypixelData {
"^\\s*(?:§.)+Party (?:§.)+\\((?<amount>\\d+)\\)\\s*$",
)

/**
* REGEX-TEST: §r§b§lIsland
*/
private val soloProfileAmountPattern by patternGroup.pattern(
"solo.profile.amount",
"^\\s*(?:§.)*Island\\s*$",
)

/**
* REGEX-TEST: §a✌ §7(§a11§7/20)
*/
Expand Down Expand Up @@ -178,6 +172,8 @@ object HypixelData {
var skyBlockArea: String? = null
var skyBlockAreaWithSymbol: String? = null

var playerAmountOnIsland = 0

// Data from locraw
var locrawData: JsonObject? = null
private val locraw: MutableMap<String, String> = listOf(
Expand Down Expand Up @@ -263,7 +259,6 @@ object HypixelData {
var amount = 0
val playerPatternList = mutableListOf(
playerAmountPattern,
playerAmountCoopPattern,
playerAmountGuestingPattern,
)
if (DungeonAPI.inDungeon()) {
Expand All @@ -278,14 +273,17 @@ object HypixelData {
}
}
}
amount += TabListData.getTabList().count { soloProfileAmountPattern.matches(it) }

return amount
if (!inAnyIsland(IslandType.GARDEN, IslandType.GARDEN_GUEST, IslandType.PRIVATE_ISLAND, IslandType.PRIVATE_ISLAND_GUEST)) {
playerAmountOnIsland = 0
}

return amount + playerAmountOnIsland
}

fun getMaxPlayersForCurrentServer(): Int {
scoreboardVisitingAmountPattern.firstMatcher(ScoreboardData.sidebarLinesFormatted) {
return group("maxamount").toInt()
return group("maxamount").toInt() + playerAmountOnIsland
}

return when (skyBlockIsland) {
Expand Down Expand Up @@ -449,6 +447,8 @@ object HypixelData {
when (event.widget) {
TabWidget.AREA -> checkIsland(event)
TabWidget.PROFILE -> checkProfile()
TabWidget.COOP -> countPlayersOnIsland(event)
TabWidget.ISLAND -> countPlayersOnIsland(event)
else -> Unit
}
}
Expand Down Expand Up @@ -570,4 +570,9 @@ object HypixelData {
val scoreboardTitle = displayName.removeColor()
return scoreboardTitlePattern.matches(scoreboardTitle)
}

private fun countPlayersOnIsland(event: WidgetUpdateEvent) {
if (event.isClear()) return
playerAmountOnIsland = playerAmountOnIslandPattern.allMatches(event.lines).size
}
}
4 changes: 4 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ enum class TabWidget(
// language=RegExp
"(?:§.)*Coop (?:§.)*.*",
),
ISLAND(
// language=RegExp
"(?:§.)*Island",
),
MINION(
// language=RegExp
"(?:§.)*Minions: (?:§.)*(?<used>\\d+)(?:§.)*/(?:§.)*(?<max>\\d+)",
Expand Down
Loading