Skip to content

Commit

Permalink
Backend: /shdebugscoreboard (hannibal002#2412)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
hannibal002 and hannibal002 authored Aug 31, 2024
1 parent d298d2a commit 96423e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.data.GardenCropMilestonesCommunityFix
import at.hannibal2.skyhanni.data.GuiEditManager
import at.hannibal2.skyhanni.data.PartyAPI
import at.hannibal2.skyhanni.data.SackAPI
import at.hannibal2.skyhanni.data.ScoreboardData
import at.hannibal2.skyhanni.data.TitleManager
import at.hannibal2.skyhanni.data.bazaar.HypixelBazaarFetcher
import at.hannibal2.skyhanni.features.bingo.card.BingoCardDisplay
Expand Down Expand Up @@ -470,6 +471,10 @@ object Commands {
"Sets the current skyblock island for testing purposes.",
) { SkyBlockIslandTest.onCommand(it) }
registerCommand("shdebugprice", "Debug different price sources for an item.") { ItemPriceUtils.debugItemPrice(it) }
registerCommand(
"shdebugscoreboard",
"Monitors the scoreboard changes: Prints the raw scoreboard lines in the console after each update, with time since last update.",
) { ScoreboardData.toggleMonitor() }
}

private fun developersCodingHelp() {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import at.hannibal2.skyhanni.events.RawScoreboardUpdateEvent
import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent
import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.lastColorCode
import at.hannibal2.skyhanni.utils.TimeUtils.format
import net.minecraft.client.Minecraft
import net.minecraft.network.play.server.S3CPacketUpdateScore
import net.minecraft.network.play.server.S3EPacketTeams
Expand Down Expand Up @@ -70,19 +73,41 @@ object ScoreboardData {
if (event.packet is S3CPacketUpdateScore) {
if (event.packet.objectiveName == "update") {
dirty = true
monitor()
}
}
if (event.packet is S3EPacketTeams) {
if (event.packet.name.startsWith("team_")) {
dirty = true
monitor()
}
}
}

private var monitor = false
private var lastMonitorState = emptyList<String>()
private var lastChangeTime = SimpleTimeMark.farPast()

private fun monitor() {
if (!monitor) return
val currentList = fetchScoreboardLines()
if (lastMonitorState != currentList) {
val time = lastChangeTime.passedSince()
lastChangeTime = SimpleTimeMark.now()
println("Scoreboard Monitor: (new change after ${time.format(showMilliSeconds = true)})")
for (s in currentList) {
println("'$s'")
}
}
lastMonitorState = currentList
println(" ")
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onTick(event: LorenzTickEvent) {
if (!dirty) return
dirty = false
monitor()

val list = fetchScoreboardLines().reversed()
val semiFormatted = list.map { cleanSB(it) }
Expand All @@ -99,6 +124,13 @@ object ScoreboardData {
}
}

fun toggleMonitor() {
monitor = !monitor
val action = if (monitor) "Enabled" else "Disabled"
ChatUtils.chat("$action scoreboard monitoring in the console.")

}

private fun cleanSB(scoreboard: String): String {
return scoreboard.toCharArray().filter { it.code in 21..126 || it.code == 167 }.joinToString(separator = "")
}
Expand Down

0 comments on commit 96423e4

Please sign in to comment.