Skip to content

Commit

Permalink
fixed npe
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunderblade73 committed Jan 6, 2025
1 parent 813ea35 commit 6f2d5c9
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/main/java/at/hannibal2/skyhanni/features/gui/ShTrack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ object ShTrack {
result.shouldAutoDelete = autoDelete
result.shouldSave = shouldSave
result.line = result.generateLine()
val tracker = tracker ?: run {
errorMessage = NullPointerException("tracker").message
return
}
if (!allowDupe) {
val index = tracker.indexOfFirst { result.similarElement(it) }
if (index != -1) {
Expand All @@ -329,7 +333,7 @@ object ShTrack {
}
}

private val tracker get() = ProfileStorageData.profileSpecific!!.tracking
private val tracker get() = ProfileStorageData.profileSpecific?.tracking

class TrackingList : ArrayList<TrackingElement<*>>(), MutableList<TrackingElement<*>> {

Expand Down Expand Up @@ -466,13 +470,12 @@ object ShTrack {
reader.endObject()

try {
val tracker: TrackingElement<*> =
when (map["type"]?.asString) {
PowderTrackingElement::class.simpleName -> PowderTrackingElement.fromJson(map)
ItemsStackElement::class.simpleName -> ItemsStackElement.fromJson(map)
ItemTrackingElement::class.simpleName -> ItemTrackingElement.fromJson(map)
else -> return null
}
val tracker: TrackingElement<*> = when (map["type"]?.asString) {
PowderTrackingElement::class.simpleName -> PowderTrackingElement.fromJson(map)
ItemsStackElement::class.simpleName -> ItemsStackElement.fromJson(map)
ItemTrackingElement::class.simpleName -> ItemTrackingElement.fromJson(map)
else -> return null
}
tracker.applyMetaOptions(map)
return tracker
} catch (e: Throwable) {
Expand All @@ -494,32 +497,29 @@ object ShTrack {

@HandleEvent
fun onProfileLeave(event: ProfileLeaveEvent) {
if (ProfileStorageData.profileSpecific != null) {
tracker.deactivate()
}
tracker?.deactivate()
}

@HandleEvent
fun onProfileJoin(event: ProfileJoinEvent) {
if (ProfileStorageData.profileSpecific != null) {
tracker.activate()
}
tracker?.activate()
}

@SubscribeEvent
fun onGuiRenderGuiOverlayRender(event: GuiRenderEvent) {
if (!LorenzUtils.inSkyBlock) return
if (scheduledUpdate) {
val tracker = tracker
if (scheduledUpdate && tracker != null) {
display = Renderable.verticalEditTable(
tracker.map { it.line },
onHover = {
if (!hasGrab) {
val tracker = tracker[it]
val track = tracker[it]
RenderableTooltips.setTooltipForRender(
tracker.generateHover().map { i -> Renderable.string(i) },
track.generateHover().map { i -> Renderable.string(i) },
spacedTitle = true,
)
tracker.handleUserInput()
track.handleUserInput()
}
},
onStartGrab = { hasGrab = true },
Expand Down Expand Up @@ -780,8 +780,7 @@ object ShTrack {
fun fromJson(read: Map<String, JsonElement>): PowderTrackingElement =
PowderTrackingElement(extractType(read), read["current"]?.asLong ?: 0, read["target"]?.asLong)

private fun extractType(read: Map<String, JsonElement>) =
HotmAPI.PowderType.getValue(read["name"]!!.asString)!!
private fun extractType(read: Map<String, JsonElement>) = HotmAPI.PowderType.getValue(read["name"]!!.asString)!!
}

}
Expand Down Expand Up @@ -821,7 +820,11 @@ object ShTrack {
}

fun delete() {
tracker.remove(this)
tracker?.remove(this) ?: ErrorManager.logErrorStateWithData(
"Could not delete tracker element.",
"Tracker is null",
"element" to this,
)
}

protected abstract fun internalUpdate(amount: Number)
Expand Down

0 comments on commit 6f2d5c9

Please sign in to comment.