aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt11
2 files changed, 11 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
index fe13c5c78..a383b377e 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
@@ -394,6 +394,10 @@ object SkillAPI {
when (first) {
"levelwithxp" -> {
val xp = second.formatLong()
+ if (xp == null) {
+ ChatUtils.userError("Not a valid number: '$second'")
+ return
+ }
if (xp <= XP_NEEDED_FOR_60) {
val level = getLevel(xp)
ChatUtils.chat("With §b${xp.addSeparators()} §eXP you would be level §b$level")
@@ -410,7 +414,7 @@ object SkillAPI {
"xpforlevel" -> {
val level = second.toIntOrNull()
if (level == null) {
- ChatUtils.userError("Not a number: '$second'")
+ ChatUtils.userError("Not a valid number: '$second'")
return
}
if (level <= 60) {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index 6deee85bc..390516e0a 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -189,11 +189,11 @@ object NumberUtil {
// TODO create new function formatLong, and eventually deprecate this function.
@Deprecated("renamed", ReplaceWith("this.formatLong()"))
- fun String.formatNumber(): Long = formatLong()
+ fun String.formatNumber(): Long = formatLong() ?: error("formatNumber has a NumberFormatException with '$this'")
- fun String.formatLong(): Long = formatDouble().toLong()
+ fun String.formatLong(): Long? = formatDouble()?.toLong()
- fun String.formatDouble(): Double {
+ fun String.formatDouble(): Double? {
var text = lowercase().replace(",", "")
val multiplier = if (text.endsWith("k")) {
@@ -206,8 +206,9 @@ object NumberUtil {
text = text.substring(0, text.length - 1)
1.bilion
} else 1.0
- val d = text.toDouble()
- return d * multiplier
+ return text.toDoubleOrNull()?.let {
+ it * multiplier
+ }
}
val Int.milion get() = this * 1_000_000.0