aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/api
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-03-06 23:51:02 +0100
committerGitHub <noreply@github.com>2024-03-06 23:51:02 +0100
commit0a95a791eb57a546fb5421594abae740faf1dfdb (patch)
tree82bfc13c544a60d496bab081b66ddd73e07d62a3 /src/main/java/at/hannibal2/skyhanni/api
parent28430fe85115334fb06fb7e3cc36da819f08dace (diff)
downloadskyhanni-0a95a791eb57a546fb5421594abae740faf1dfdb.tar.gz
skyhanni-0a95a791eb57a546fb5421594abae740faf1dfdb.tar.bz2
skyhanni-0a95a791eb57a546fb5421594abae740faf1dfdb.zip
Internal Changes: Many small code cleanups (#1101)
Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/api')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt20
2 files changed, 16 insertions, 17 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
index 1e991605e..0077a6e83 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
@@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
+import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
@@ -46,10 +47,9 @@ object CollectionAPI {
val stack = event.inventoryItems[4] ?: return
loop@ for (line in stack.getLore()) {
singleCounterPattern.matchMatcher(line) {
- val counter = group("amount").replace(",", "").toLong()
+ val counter = group("amount").formatLong()
val name = inventoryName.split(" ").dropLast(1).joinToString(" ")
- val internalName = NEUItems.getInternalNameOrNull(name) ?: continue@loop
- collectionValue[internalName] = counter
+ collectionValue[NEUInternalName.fromItemName(name)] = counter
}
}
CollectionUpdateEvent().postAndCatch()
@@ -59,7 +59,7 @@ object CollectionAPI {
if (inventoryName == "Boss Collections") return
for ((_, stack) in event.inventoryItems) {
- var name = stack.name?.removeColor() ?: continue
+ var name = stack.name.removeColor()
if (name.contains("Collections")) continue
val lore = stack.getLore()
@@ -71,9 +71,8 @@ object CollectionAPI {
loop@ for (line in lore) {
counterPattern.matchMatcher(line) {
- val counter = group("amount").replace(",", "").toLong()
- val internalName = NEUItems.getInternalNameOrNull(name) ?: continue@loop
- collectionValue[internalName] = counter
+ val counter = group("amount").formatLong()
+ collectionValue[NEUInternalName.fromItemName(name)] = counter
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
index 0df046a65..64d905ccb 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
@@ -21,8 +21,9 @@ import at.hannibal2.skyhanni.utils.ChatUtils
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.formatDouble
+import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.NumberUtil.formatLongOrUserError
-import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
@@ -170,7 +171,7 @@ object SkillAPI {
val previousLine = stack.getLore()[lineIndex - 1]
val progress = cleanLine.substring(cleanLine.lastIndexOf(' ') + 1)
if (previousLine == "§7§8Max Skill level reached!") {
- var totalXp = progress.formatNumber()
+ var totalXp = progress.formatLong()
val minus = if (skillLevel == 50) 4_000_000 else if (skillLevel == 60) 7_000_000 else 0
totalXp -= minus
val (overflowLevel, overflowCurrent, overflowNeeded, overflowTotal) = getSkillInfo(
@@ -192,8 +193,8 @@ object SkillAPI {
}
} else {
val splitProgress = progress.split("/")
- val currentXp = splitProgress.first().formatNumber()
- val neededXp = splitProgress.last().formatNumber()
+ val currentXp = splitProgress.first().formatLong()
+ val neededXp = splitProgress.last().formatLong()
val levelingArray = levelArray()
val levelXp = calculateLevelXp(levelingArray, skillLevel - 1).toLong()
@@ -266,8 +267,8 @@ object SkillAPI {
}
private fun handleSkillPattern(matcher: Matcher, skillType: SkillType, skillInfo: SkillInfo) {
- val currentXp = matcher.group("current").formatNumber()
- val maxXp = matcher.group("needed").formatNumber()
+ val currentXp = matcher.group("current").formatLong()
+ val maxXp = matcher.group("needed").formatLong()
val level = getLevelExact(maxXp)
val (levelOverflow, currentOverflow, currentMaxOverflow, totalOverflow) = getSkillInfo(
@@ -311,8 +312,7 @@ object SkillAPI {
}
}
val existingLevel = getSkillInfo(skillType) ?: SkillInfo()
- val xpPercentageS = matcher.group("progress").replace(",", "")
- val xpPercentage = xpPercentageS.toFloatOrNull() ?: return
+ val xpPercentage = matcher.group("progress").formatDouble()
val levelingArray = levelArray()
val levelXp = calculateLevelXp(levelingArray, existingLevel.level - 1)
val nextLevelDiff = levelingArray[tablistLevel]?.asDouble ?: 7_600_000.0
@@ -341,8 +341,8 @@ object SkillAPI {
}
private fun handleSkillPatternMultiplier(matcher: Matcher, skillType: SkillType, skillInfo: SkillInfo) {
- val currentXp = matcher.group("current").formatNumber()
- val maxXp = matcher.group("needed").formatNumber()
+ val currentXp = matcher.group("current").formatLong()
+ val maxXp = matcher.group("needed").formatLong()
val level = getLevelExact(maxXp)
val levelingArray = levelArray()
val levelXp = calculateLevelXp(levelingArray, level - 1).toLong() + currentXp