aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt7
2 files changed, 16 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
index e309f5b66..fe13c5c78 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
@@ -18,10 +18,10 @@ import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.getSkillInfo
import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.levelArray
import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.xpRequiredForLevel
import at.hannibal2.skyhanni.utils.ChatUtils
-import at.hannibal2.skyhanni.utils.ChatUtils.userError
import at.hannibal2.skyhanni.utils.ItemUtils.cleanName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary
import at.hannibal2.skyhanni.utils.SimpleTimeMark
@@ -393,12 +393,12 @@ object SkillAPI {
val second = it[1]
when (first) {
"levelwithxp" -> {
- val xp = second.toLong()
+ val xp = second.formatLong()
if (xp <= XP_NEEDED_FOR_60) {
val level = getLevel(xp)
ChatUtils.chat("With §b${xp.addSeparators()} §eXP you would be level §b$level")
} else {
- val (overflowLevel, current, needed, _) = calculateOverFlow(second.toLong())
+ val (overflowLevel, current, needed, _) = calculateOverFlow(xp)
ChatUtils.chat(
"With §b${xp.addSeparators()} §eXP you would be level §b$overflowLevel " +
"§ewith progress (§b${current.addSeparators()}§e/§b${needed.addSeparators()}§e) XP"
@@ -408,7 +408,11 @@ object SkillAPI {
}
"xpforlevel" -> {
- val level = second.toInt()
+ val level = second.toIntOrNull()
+ if (level == null) {
+ ChatUtils.userError("Not a number: '$second'")
+ return
+ }
if (level <= 60) {
val neededXp = levelingMap.filter { it.key < level }.values.sum().toLong()
ChatUtils.chat("You need §b${neededXp.addSeparators()} §eXP to be level §b${level.toDouble()}")
@@ -424,7 +428,7 @@ object SkillAPI {
val rawSkill = it[1].lowercase()
val skillType = SkillType.getByNameOrNull(rawSkill)
if (skillType == null) {
- userError("Unknown Skill type: $rawSkill")
+ ChatUtils.userError("Unknown Skill type: $rawSkill")
return
}
val skill = storage?.get(skillType) ?: return
@@ -439,19 +443,19 @@ object SkillAPI {
val rawSkill = it[1].lowercase()
val skillType = SkillType.getByNameOrNull(rawSkill)
if (skillType == null) {
- userError("Unknown Skill type: $rawSkill")
+ ChatUtils.userError("Unknown Skill type: $rawSkill")
return
}
val rawLevel = it[2]
val targetLevel = rawLevel.toIntOrNull()
if (targetLevel == null) {
- userError("$rawLevel is not a valid number.")
+ ChatUtils.userError("$rawLevel is not a valid number.")
return
}
val skill = storage?.get(skillType) ?: return
if (targetLevel <= skill.overflowLevel) {
- userError("Custom goal level ($targetLevel) must be greater than your current level (${skill.overflowLevel}).")
+ ChatUtils.userError("Custom goal level ($targetLevel) must be greater than your current level (${skill.overflowLevel}).")
return
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index 4e00a85e7..6deee85bc 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -3,8 +3,6 @@ package at.hannibal2.skyhanni.utils
import java.text.NumberFormat
import java.util.Locale
import java.util.TreeMap
-import kotlin.math.max
-import kotlin.math.min
import kotlin.math.pow
import kotlin.math.roundToInt
@@ -190,7 +188,10 @@ object NumberUtil {
}
// TODO create new function formatLong, and eventually deprecate this function.
- fun String.formatNumber(): Long = formatDouble().toLong()
+ @Deprecated("renamed", ReplaceWith("this.formatLong()"))
+ fun String.formatNumber(): Long = formatLong()
+
+ fun String.formatLong(): Long = formatDouble().toLong()
fun String.formatDouble(): Double {
var text = lowercase().replace(",", "")