Skip to content

Commit

Permalink
Fix: Custom Scoreboard Player Count Including Offline Players (#3026)
Browse files Browse the repository at this point in the history
Co-authored-by: Chiss5618 <78828070+Chiss5618@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 13, 2024
1 parent c67724a commit ad2ef78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
37 changes: 21 additions & 16 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(
"playeramount.coop",
"^\\s*(?:§.)*Coop (?:§.)*\\((?<amount>\\d+)\\)\\s*$",
private val playerAmountOnIslandPattern by patternGroup.pattern(
"playeramount.onisland",
"^§.\\[[§\\w]{6,11}] §r.*",
)

/**
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 @@ -119,6 +119,10 @@ enum class TabWidget(
// language=RegExp
"(?:§.)*Coop (?:§.)*.*",
),
ISLAND(
// language=RegExp
"(?:§.)*Island",
),
MINION(
// language=RegExp
"(?:§.)*Minions: (?:§.)*(?<used>\\d+)(?:§.)*/(?:§.)*(?<max>\\d+)",
Expand Down

0 comments on commit ad2ef78

Please sign in to comment.