From b98cfd9c8a6da8d24063e37f9e333de5abe0681f Mon Sep 17 00:00:00 2001 From: martimavocado <39881008+martimavocado@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:08:42 +0000 Subject: Fix : /playtimedetailed tooltip generation, limbostats with negative luck (#1307) --- .../skyhanni/features/misc/limbo/LimboPlaytime.kt | 20 ++++++++++++++++---- .../skyhanni/features/misc/limbo/LimboTimeTracker.kt | 15 +++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt index cf0da4b6c..b232b837d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt @@ -137,10 +137,22 @@ class LimboPlaytime { minutesList: MutableList, hoursList: MutableList, ) { - val firstLine = toolTip.first() - val totalPlaytime = toolTip.last() + val firstList = mutableListOf() + val lastList = mutableListOf() + var hasPassed = false + toolTip.forEach { + if (!(hoursPattern.matches(it) || minutesPattern.matches(it)) && !hasPassed) { + firstList.add(it) + } else hasPassed = true + } + hasPassed = false + toolTip.forEach { + if (!(hoursPattern.matches(it) || minutesPattern.matches(it)) && hasPassed) { + lastList.add(it) + } else hasPassed = true + } toolTip.clear() - toolTip.add(firstLine) + toolTip.addAll(firstList) if (!setMinutes) { toolTip.addAll(modifiedList) toolTip.addAll(minutesList) @@ -148,7 +160,7 @@ class LimboPlaytime { toolTip.addAll(hoursList) toolTip.addAll(modifiedList) } - toolTip.add(totalPlaytime) + toolTip.addAll(lastList) } private fun findFloatDecimalPlace(input: Float): Int { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboTimeTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboTimeTracker.kt index e39736326..9e9a9113f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboTimeTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboTimeTracker.kt @@ -147,8 +147,13 @@ object LimboTimeTracker { val currentPB = storage?.personalBest ?: 0 val userLuck = storage?.userLuck ?: 0f val limboPB: Int = if (currentPB < timeInLimbo) timeInLimbo else currentPB - ChatUtils.chat("§fYour current PB is §e${limboPB.seconds}§f, granting you §a+${userLuck.round(2)}✴ SkyHanni User Luck§f!") - ChatUtils.chat("§fYou have §e${playtime.seconds} §fof playtime!") + var luckString = tryTruncateFloat(userLuck.round(2)) + if (userLuck > 0) luckString = "+$luckString" + var firstMessage = "§fYour current PB is §e${limboPB.seconds}§f, granting you §a$luckString✴ SkyHanni User Luck§f!" + val secondMessage = "§fYou have §e${playtime.seconds} §fof playtime!" + if ((userLuck == Float.POSITIVE_INFINITY) || (userLuck == Float.NEGATIVE_INFINITY)) firstMessage = "$firstMessage §Zwhat" + ChatUtils.chat(firstMessage) + ChatUtils.chat(secondMessage) } } @@ -189,4 +194,10 @@ object LimboTimeTracker { } fun isEnabled() = config.showTimeInLimbo + + private fun tryTruncateFloat(input: Float): String { + val string = input.toString() + return if (string.endsWith(".0")) return string.dropLast(2) + else string + } } -- cgit