Skip to content

Commit

Permalink
Fix: Item data sometimes not loading (#3191)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs authored Jan 11, 2025
1 parent 7d40695 commit 20d661b
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.data.jsonobjects.repo.neu.NeuPetsJson
import at.hannibal2.skyhanni.events.HypixelJoinEvent
import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
Expand Down Expand Up @@ -363,6 +364,19 @@ object EnoughUpdatesManager {
}
}

private fun itemCountInRepoFolder(): Int {
val itemsFolder = File(repoLocation, "items")
return itemsFolder.listFiles()?.size ?: 0
}

@HandleEvent
fun onHypixelJoin(event: HypixelJoinEvent) {
if (itemMap.isEmpty() && itemCountInRepoFolder() > 0) {
reloadRepo()
println("No loaded items in NEU repo, attempting to reload the repo.")
}
}

@HandleEvent
fun onNeuRepoReload(event: NeuRepositoryReloadEvent) {
neuPetsJson = event.readConstant<NeuPetsJson>("pets")
Expand All @@ -385,5 +399,23 @@ object EnoughUpdatesManager {
callback { downloadRepo() }
}
}

event.register("shneurepostatus") {
description = "Get the status of the NEU repo"
category = CommandCategory.DEVELOPER_TEST
callback {
val loadedItems = itemMap.size
val directorySize = itemCountInRepoFolder()

ChatUtils.chat("NEU Repo Status:")
when {
directorySize == 0 -> ChatUtils.chat("§cNo items directory found!", prefix = false)
loadedItems == 0 -> ChatUtils.chat("§cNo items loaded!", prefix = false)
loadedItems < directorySize -> ChatUtils.chat("§eLoaded $loadedItems/$directorySize items", prefix = false)
loadedItems > directorySize -> ChatUtils.chat("§eLoaded Items: $loadedItems (more than directory size)", prefix = false)
else -> ChatUtils.chat("§aLoaded all $loadedItems items!", prefix = false)
}
}
}
}
}

0 comments on commit 20d661b

Please sign in to comment.