From ef46ba9c02d395f6c884a3b819810ec394e6759b Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 25 Feb 2024 10:02:19 +0100 Subject: Added support for number abbreviations in /shskills. --- src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/api') 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 } -- cgit