diff options
Diffstat (limited to 'src/main')
82 files changed, 352 insertions, 339 deletions
diff --git a/src/main/java/SkyHanniInstallerFrame.java b/src/main/java/SkyHanniInstallerFrame.java index dee06da43..9381e9aef 100644 --- a/src/main/java/SkyHanniInstallerFrame.java +++ b/src/main/java/SkyHanniInstallerFrame.java @@ -642,25 +642,6 @@ public class SkyHanniInstallerFrame extends JFrame implements ActionListener, Mo return version; } -// private String getVersionFromMcmodInfo() { -// String version = ""; -// try { -// BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(getClass() -// .getClassLoader() -// .getResourceAsStream("mcmod.info"), "mcmod.info not found."))); -// while ((version = bufferedReader.readLine()) != null) { -// if (version.contains("\"version\": \"")) { -// version = version.split(Pattern.quote("\"version\": \""))[1]; -// version = version.substring(0, version.length() - 2); -// break; -// } -// } -// } catch (Exception ex) { -// // It's okay, I guess just don't use the version lol. -// } -// return version; -// } - private File getThisFile() { try { return new File(SkyHanniInstallerFrame.class 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 diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt index 138158ccb..64eac452b 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt @@ -16,8 +16,7 @@ class GardenComposterUpgradesData { if (!GardenAPI.inGarden()) return if (event.inventoryName != "Composter Upgrades") return for (item in event.inventoryItems.values) { - val itemName = item.name ?: continue - ComposterUpgrade.regex.matchMatcher(itemName) { + ComposterUpgrade.regex.matchMatcher(item.name) { val name = group("name") val level = group("level")?.romanToDecimalIfNecessary() ?: 0 val composterUpgrade = ComposterUpgrade.getByName(name)!! diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesCommunityFix.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesCommunityFix.kt index e38e3d075..c52878003 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesCommunityFix.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesCommunityFix.kt @@ -13,7 +13,8 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -79,8 +80,7 @@ object GardenCropMilestonesCommunityFix { crop: CropType, wrongData: MutableList<String>, ) { - val name = stack.name ?: return - val rawNumber = name.removeColor().replace(crop.cropName, "").trim() + val rawNumber = stack.name.removeColor().replace(crop.cropName, "").trim() val realTier = if (rawNumber == "") 0 else rawNumber.romanToDecimalIfNecessary() val lore = stack.getLore() @@ -97,7 +97,7 @@ object GardenCropMilestonesCommunityFix { ) - GardenCropMilestones.getCropsForTier(realTier, crop) // debug("guessNextMax: ${guessNextMax.addSeparators()}") val nextMax = amountPattern.matchMatcher(next) { - group("max").formatNumber() + group("max").formatLong() } ?: return // debug("nextMax real: ${nextMax.addSeparators()}") if (nextMax != guessNextMax) { @@ -108,7 +108,7 @@ object GardenCropMilestonesCommunityFix { val guessTotalMax = GardenCropMilestones.getCropsForTier(46, crop) // println("guessTotalMax: ${guessTotalMax.addSeparators()}") val totalMax = amountPattern.matchMatcher(total) { - group("max").formatNumber() + group("max").formatLong() } ?: return // println("totalMax real: ${totalMax.addSeparators()}") val totalOffBy = guessTotalMax - totalMax @@ -150,7 +150,7 @@ object GardenCropMilestonesCommunityFix { val (rawCrop, tier, amount) = split val crop = LorenzUtils.enumValueOf<CropType>(rawCrop) - if (tryFix(crop, tier.toInt(), amount.formatNumber().toInt())) { + if (tryFix(crop, tier.toInt(), amount.formatInt())) { fixed++ } else { alreadyCorrect++ diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt index c15299ab3..e6c810852 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt @@ -31,7 +31,7 @@ class GardenCropUpgrades { fun onInventoryOpen(event: InventoryFullyOpenedEvent) { if (event.inventoryName != "Crop Upgrades") return event.inventoryItems.forEach { (_, item) -> - val crop = item.name?.removeColor()?.let { CropType.getByNameOrNull(it) } ?: return@forEach + val crop = CropType.getByNameOrNull(item.name.removeColor()) ?: return@forEach val level = item.getLore() .firstNotNullOfOrNull { tierPattern.matchEntire(it)?.groups?.get(1)?.value?.toIntOrNull() } ?: 0 crop.setUpgradeLevel(level) diff --git a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt index 73ca7ca17..e42bdb8af 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt @@ -19,7 +19,8 @@ import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull import at.hannibal2.skyhanni.utils.NEUItems.getPrice -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt +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 @@ -99,12 +100,12 @@ object SackAPI { } private fun NEUInternalName.sackPrice(stored: String) = when (sackDisplayConfig.priceFrom) { - PriceFrom.BAZAAR -> (getPrice(true) * stored.formatNumber()).toLong() + PriceFrom.BAZAAR -> (getPrice(true) * stored.formatLong()).toLong() .let { if (it < 0) 0L else it } PriceFrom.NPC -> try { val npcPrice = getNpcPriceOrNull() ?: 0.0 - (npcPrice * stored.formatNumber()).toLong() + (npcPrice * stored.formatLong()).toLong() } catch (e: Exception) { 0L } @@ -115,7 +116,7 @@ object SackAPI { fun getSacksData(savingSacks: Boolean) { if (savingSacks) sackData = ProfileStorageData.sackProfiles?.sackContents ?: return for ((_, stack) in stackList) { - val name = stack.name ?: continue + val name = stack.name val lore = stack.getLore() val gem = SackGemstone() val rune = SackRune() @@ -135,19 +136,19 @@ object SackAPI { "Rough" -> { gem.rough = stored gem.roughPrice = internalName.sackPrice(stored) - if (savingSacks) setSackItem(internalName, stored.formatNumber()) + if (savingSacks) setSackItem(internalName, stored.formatLong()) } "Flawed" -> { gem.flawed = stored gem.flawedPrice = internalName.sackPrice(stored) - if (savingSacks) setSackItem(internalName, stored.formatNumber()) + if (savingSacks) setSackItem(internalName, stored.formatLong()) } "Fine" -> { gem.fine = stored gem.finePrice = internalName.sackPrice(stored) - if (savingSacks) setSackItem(internalName, stored.formatNumber()) + if (savingSacks) setSackItem(internalName, stored.formatLong()) } } gemstoneItem[name] = gem @@ -162,10 +163,10 @@ object SackAPI { item.stored = stored item.total = group("total") - if (savingSacks) setSackItem(item.internalName, item.stored.formatNumber()) + if (savingSacks) setSackItem(item.internalName, item.stored.formatLong()) item.price = if (isTrophySack) { val filletPerTrophy = FishingAPI.getFilletPerTrophy(stack.getInternalName()) - val filletValue = filletPerTrophy * stored.formatNumber() + val filletValue = filletPerTrophy * stored.formatLong() item.magmaFish = filletValue "MAGMA_FISH".asInternalName().sackPrice(filletValue.toString()) } else { @@ -227,7 +228,7 @@ object SackAPI { val sackChanges = ArrayList<SackChange>() for (match in sackChangeRegex.findAll(sackChangeText)) { - val delta = match.groups[1]!!.value.replace(",", "").toInt() + val delta = match.groups[1]!!.value.formatInt() val item = match.groups[2]!!.value val sacks = match.groups[3]!!.value.split(", ") diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt index 78a44cda3..5a6c7c819 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt @@ -7,7 +7,7 @@ import at.hannibal2.skyhanni.events.SkillExpGainEvent import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -40,8 +40,8 @@ class SkillExperience { actionBarPattern.matchMatcher(event.actionBar) { val skill = group("skill").lowercase() - val overflow = group("overflow").formatNumber() - val neededForNextLevel = group("needed").formatNumber() + val overflow = group("overflow").formatLong() + val neededForNextLevel = group("needed").formatLong() val nextLevel = getLevelForExpExactly(neededForNextLevel) val baseExp = getExpForLevel(nextLevel - 1) val totalExp = baseExp + overflow @@ -59,7 +59,7 @@ class SkillExperience { if (event.inventoryName != "Your Skills") return for ((_, stack) in event.inventoryItems) { - val name = stack.name?.removeColor() ?: continue + val name = stack.name.removeColor() if (!name.contains(" ")) continue val lore = stack.getLore() @@ -76,8 +76,7 @@ class SkillExperience { val level = split[1].romanToDecimal() val baseExp = getExpForLevel(level) inventoryPattern.matchMatcher(line) { - val rawNumber = group("number") - val overflow = rawNumber.formatNumber() + val overflow = group("number").formatLong() val experience = baseExp + overflow skillExp[skillName] = experience } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/FirstMinionTier.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/FirstMinionTier.kt index e6d339979..e4bae4f05 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/FirstMinionTier.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/FirstMinionTier.kt @@ -43,7 +43,7 @@ object FirstMinionTier { minionId: NEUInternalName, ) { if (recipe.getCachedIngredients().any { help.contains(it.internalItemId.asInternalName()) }) { - val name = recipe.output.itemStack.name!!.removeColor() + val name = recipe.output.itemStack.name.removeColor() val abc = name.replace(" I", " 0") minions[abc] = minionId.replace("_1", "_0") } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt index a6f81c588..35741622a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt @@ -15,6 +15,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getCachedIngredients +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -222,8 +223,8 @@ class MinionCraftHelper { return } val format = LorenzUtils.formatPercentage(percentage) - val haveFormat = LorenzUtils.formatInteger(have) - val needFormat = LorenzUtils.formatInteger(needAmount) + val haveFormat = have.addSeparators() + val needFormat = needAmount.addSeparators() newDisplay.add("$itemName§8: §e$format §8(§7$haveFormat§8/§7$needFormat§8)") allDone = false } @@ -265,7 +266,7 @@ class MinionCraftHelper { if (event.inventoryName != "Crafted Minions") return for ((_, b) in event.inventoryItems) { - val name = b.name ?: continue + val name = b.name if (!name.startsWith("§e")) continue val internalName = NEUInternalName.fromItemName("$name I") .replace("MINION", "GENERATOR").replace(";", "_").replace("CAVE_SPIDER", "CAVESPIDER") diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt index c0606ad54..91759f003 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt @@ -51,7 +51,7 @@ class BingoCardReader { lore.any { it.endsWith("Community Goal") } -> GoalType.COMMUNITY else -> continue } - val name = stack.name?.removeColor() ?: continue + val name = stack.name.removeColor() var index = 0 val builder = StringBuilder() for (s in lore) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/nextstephelper/BingoNextStepHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/nextstephelper/BingoNextStepHelper.kt index be4a8c7a4..30dd81bd7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/nextstephelper/BingoNextStepHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/nextstephelper/BingoNextStepHelper.kt @@ -22,6 +22,8 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -122,9 +124,7 @@ class BingoNextStepHelper { return if (having > 0) { val needed = step.amountNeeded val percentage = LorenzUtils.formatPercentage(having.toDouble() / needed) - val havingFormat = LorenzUtils.formatInteger(having) - val neededFormat = LorenzUtils.formatInteger(needed) - " $percentage ($havingFormat/$neededFormat)" + " $percentage (${having.addSeparators()}/${needed.addSeparators()})" } else "" } } @@ -183,7 +183,7 @@ class BingoNextStepHelper { if (step is ItemsStep) { var totalCount = 0L for ((itemName, multiplier) in step.variants) { - val count = InventoryUtils.countItemsInLowerInventory { it.name?.removeColor() == itemName } + val count = InventoryUtils.countItemsInLowerInventory { it.name.removeColor() == itemName } totalCount += count * multiplier } if (step.amountHaving != totalCount) { @@ -263,7 +263,7 @@ class BingoNextStepHelper { private fun readDescription(description: String): NextStep? { collectionPattern.matchMatcher(description) { - val amount = group("amount").replace(",", "").toInt() + val amount = group("amount").formatInt() val name = group("name") return CollectionStep(name, amount) withItemIslandRequirement name diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/BestiaryData.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/BestiaryData.kt index bd1d58894..2e9259f0a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/BestiaryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/BestiaryData.kt @@ -18,7 +18,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addButton import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.NumberUtil.roundToPrecision import at.hannibal2.skyhanni.utils.NumberUtil.toRoman @@ -150,12 +150,12 @@ object BestiaryData { val progress = line.substring(line.lastIndexOf(' ') + 1) if (previousLine.contains("Families Found")) { progressPattern.matchMatcher(progress) { - familiesFound = group("current").formatNumber() - totalFamilies = group("needed").formatNumber() + familiesFound = group("current").formatLong() + totalFamilies = group("needed").formatLong() } } else if (previousLine.contains("Families Completed")) { progressPattern.matchMatcher(progress) { - familiesCompleted = group("current").formatNumber() + familiesCompleted = group("current").formatLong() } } } @@ -178,7 +178,7 @@ object BestiaryData { for ((lineIndex, line) in stack.getLore().withIndex()) { val loreLine = line.removeColor() if (loreLine.startsWith("Kills: ")) { - actualRealTotalKill = "([0-9,.]+)".toRegex().find(loreLine)?.groupValues?.get(1)?.formatNumber() + actualRealTotalKill = "([0-9,.]+)".toRegex().find(loreLine)?.groupValues?.get(1)?.formatLong() ?: 0 } if (!loreLine.startsWith(" ")) continue @@ -186,13 +186,13 @@ object BestiaryData { val progress = loreLine.substring(loreLine.lastIndexOf(' ') + 1) if (previousLine.contains("Progress to Tier")) { progressPattern.matchMatcher(progress) { - totalKillToTier = group("needed").formatNumber() - currentKillToTier = group("current").formatNumber() + totalKillToTier = group("needed").formatLong() + currentKillToTier = group("current").formatLong() } } else if (previousLine.contains("Overall Progress")) { progressPattern.matchMatcher(progress) { - totalKillToMax = group("needed").formatNumber() - currentTotalKill = group("current").formatNumber() + totalKillToMax = group("needed").formatLong() + currentTotalKill = group("current").formatLong() } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt index b87002c0e..274e64f9d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt @@ -18,7 +18,6 @@ import at.hannibal2.skyhanni.features.dungeon.DungeonAPI import at.hannibal2.skyhanni.features.slayer.blaze.HellionShield import at.hannibal2.skyhanni.features.slayer.blaze.setHellionShield import at.hannibal2.skyhanni.test.command.ErrorManager -import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy import at.hannibal2.skyhanni.utils.CollectionUtils.put import at.hannibal2.skyhanni.utils.ConfigUtils @@ -400,7 +399,13 @@ class DamageIndicatorManager { val thorn = checkThorn(health, maxHealth) if (thorn == null) { val floor = DungeonAPI.dungeonFloor - ChatUtils.error("problems with thorn detection! ($floor, $health/$maxHealth)") + ErrorManager.logErrorStateWithData( + "Could not detect thorn", + "checkThorn returns null", + "health" to health, + "maxHealth" to maxHealth, + "floor" to floor, + ) } return thorn } @@ -563,7 +568,16 @@ class DamageIndicatorManager { calcHealth = 0 break } else { - ChatUtils.error("unknown magma boss health sidebar format!") + ErrorManager.logErrorStateWithData( + "Unknown magma boss health sidebar format", + "Damage Indicator could not find magma boss bar data", + "line" to line, + "ScoreboardData.sidebarLinesRaw" to ScoreboardData.sidebarLinesRaw, + "calcHealth" to calcHealth, + "slimeSize" to slimeSize, + "entity" to entity, + "entityData" to entityData, + ) break } @@ -777,7 +791,11 @@ class DamageIndicatorManager { } } } else { - ChatUtils.error("Invalid/impossible thorn floor!") + ErrorManager.logErrorStateWithData( + "Thorn in wrong floor detected", + "Invalid floor for thorn", + "dungeonFloor" to DungeonAPI.dungeonFloor, + ) return null } val color = NumberUtil.percentageColor(health.toLong(), maxHealth.toLong()) diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonFinderFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonFinderFeatures.kt index d636f24e3..9c352a459 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonFinderFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonFinderFeatures.kt @@ -40,7 +40,7 @@ class DungeonFinderFeatures { if (!LorenzUtils.inSkyBlock || LorenzUtils.skyBlockArea != "Dungeon Hub") return if (!config.floorAsStackSize) return - val itemName = event.stack.name?.removeColor() ?: "" + val itemName = event.stack.name.removeColor() val invName = InventoryUtils.openInventoryName() if (invName == "Select Floor") { @@ -105,8 +105,7 @@ class DungeonFinderFeatures { if (slot.slotNumber != slot.slotIndex) continue if (slot.stack == null) continue - val itemName = slot.stack.name ?: continue - if (!itemName.endsWith(" Party")) continue + if (!slot.stack.name.endsWith(" Party")) continue if (config.markIneligibleGroups && slot.stack.getLore().any { ineligiblePattern.matches(it) }) { slot highlight LorenzColor.DARK_RED diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/AllBurrowsList.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/AllBurrowsList.kt index f28c4966f..3ff3fa59f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/AllBurrowsList.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/AllBurrowsList.kt @@ -7,7 +7,6 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.drawColor @@ -43,7 +42,7 @@ object AllBurrowsList { val burrowLocations = burrowLocations ?: return val list = burrowLocations.map { it.printWithAccuracy(0, ":") } OSUtils.copyToClipboard(list.joinToString(";")) - LorenzUtils.chat("Saved all ${list.size} burrow locations to clipboard.") + ChatUtils.chat("Saved all ${list.size} burrow locations to clipboard.") } fun addFromClipboard() { diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/BasketWaypoints.kt b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/BasketWaypoints.kt index 2d96a88b9..1eae1e8a6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/BasketWaypoints.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/BasketWaypoints.kt @@ -11,7 +11,6 @@ import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled import at.hannibal2.skyhanni.utils.LocationUtils.distanceSqToPlayer import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.anyContains import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -94,9 +93,12 @@ class BasketWaypoints { return if (config.onlyClosest) closest == this else true } + // TODO use regex with the help of knowing the original lore. Will most likely need to wait until next halloween event private fun checkScoreboardHalloweenSpecific(): Boolean { - val list = ScoreboardData.sidebarLinesFormatted - return list.anyContains("Hypixel Level") && list.anyContains("Halloween") && list.anyContains("Baskets") + val a = ScoreboardData.sidebarLinesFormatted.any { it.contains("Hypixel Level") } + val b = ScoreboardData.sidebarLinesFormatted.any { it.contains("Halloween") } + val c = ScoreboardData.sidebarLinesFormatted.any { it.contains("Baskets") } + return a && b && c } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt index 37c92d5c0..786719391 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt @@ -13,14 +13,19 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.TimeUtils @@ -100,10 +105,9 @@ class CityProjectFeatures { if (config.showMaterials) { // internal name -> amount - val materials = mutableMapOf<String, Int>() + val materials = mutableMapOf<NEUInternalName, Int>() for ((_, item) in event.inventoryItems) { - val itemName = item.name ?: continue - if (itemName != "§eContribute this component!") continue + if (item.name != "§eContribute this component!") continue fetchMaterials(item, materials) } @@ -111,9 +115,9 @@ class CityProjectFeatures { } if (config.showReady) { - var nextTime = Long.MAX_VALUE + var nextTime = SimpleTimeMark.farFuture() + val now = SimpleTimeMark.now() for ((_, item) in event.inventoryItems) { - val itemName = item.name ?: continue val lore = item.getLore() val completed = lore.lastOrNull()?.let { completedPattern.matches(it) } ?: false @@ -122,17 +126,17 @@ class CityProjectFeatures { contributeAgainPattern.matchMatcher(line) { val rawTime = group("time") if (rawTime.contains("Soon!")) return@matchMatcher - val duration = TimeUtils.getMillis(rawTime) - val endTime = System.currentTimeMillis() + duration + val duration = TimeUtils.getDuration(rawTime) + val endTime = now + duration if (endTime < nextTime) { nextTime = endTime } } } - if (itemName != "§eContribute this component!") continue - nextTime = System.currentTimeMillis() + if (item.name != "§eContribute this component!") continue + nextTime = now } - ProfileStorageData.playerSpecific?.nextCityProjectParticipationTime = nextTime + ProfileStorageData.playerSpecific?.nextCityProjectParticipationTime = nextTime.toMillis() } } @@ -143,7 +147,7 @@ class CityProjectFeatures { return true } - private fun buildList(materials: MutableMap<String, Int>) = buildList<List<Any>> { + private fun buildList(materials: MutableMap<NEUInternalName, Int>) = buildList<List<Any>> { addAsSingletonList("§7City Project Materials") if (materials.isEmpty()) { @@ -152,8 +156,8 @@ class CityProjectFeatures { } for ((internalName, amount) in materials) { - val stack = NEUItems.getItemStack(internalName) - val name = stack.name ?: continue + val stack = internalName.getItemStack() + val name = internalName.itemName val list = mutableListOf<Any>() list.add(" §7- ") list.add(stack) @@ -166,14 +170,14 @@ class CityProjectFeatures { } }) { inInventory && !NEUItems.neuHasFocus() }) - val price = NEUItems.getPrice(internalName) * amount + val price = internalName.getPrice(false) * amount val format = NumberUtil.format(price) list.add(" §7(§6$format§7)") add(list) } } - private fun fetchMaterials(item: ItemStack, materials: MutableMap<String, Int>) { + private fun fetchMaterials(item: ItemStack, materials: MutableMap<NEUInternalName, Int>) { var next = false val lore = item.getLore() val completed = lore.lastOrNull()?.let { completedPattern.matches(it) } ?: false @@ -188,7 +192,7 @@ class CityProjectFeatures { if (line.contains("Bits")) break val (name, amount) = ItemUtils.readItemAmount(line) ?: continue - val internalName = NEUItems.getRawInternalName(name) + val internalName = NEUInternalName.fromItemName(name) val old = materials.getOrPut(internalName) { 0 } materials[internalName] = old + amount } diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt index 3335f61ca..2403e430f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt @@ -12,13 +12,13 @@ import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.getFillet import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemCategory +import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.client.Minecraft import net.minecraft.entity.item.EntityArmorStand @@ -85,11 +85,9 @@ object FishingAPI { } private fun NEUInternalName.isFishingRod() = contains("ROD") + fun ItemStack.isFishingRod() = getItemCategoryOrNull() == ItemCategory.FISHING_ROD || getItemCategoryOrNull() == ItemCategory.FISHING_WEAPON - fun ItemStack.isBait(): Boolean { - val name = name ?: return false - return stackSize == 1 && (name.removeColor().startsWith("Obfuscated") || name.endsWith(" Bait")) - } + fun ItemStack.isBait(): Boolean = stackSize == 1 && getItemCategoryOrNull() == ItemCategory.FISHING_BAIT @SubscribeEvent fun onItemInHandChange(event: ItemInHandChangeEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt index 352b36d16..854165823 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt @@ -69,10 +69,9 @@ class FishingBaitWarnings { for (entity in EntityUtils.getEntitiesNearby<EntityItem>(bobber.getLorenzVec(), 6.0)) { val itemStack = entity.entityItem ?: continue if (!itemStack.isBait()) continue - val name = itemStack.name ?: continue val ticksExisted = entity.ticksExisted if (ticksExisted in 6..15) { - return name + return itemStack.name } val distance = "distance: ${entity.getDistanceToEntity(bobber).addSeparators()}" diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt index e2d1b297e..28c2aa27f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt @@ -49,7 +49,7 @@ class ShowFishingItemName { val location = event.exactLocation(entityItem).add(y = 0.8) if (location.distance(LocationUtils.playerLocation()) > 15) continue val itemStack = entityItem.entityItem - var name = itemStack.name ?: continue + var name = itemStack.name // Hypixel sometimes replaces the bait item mid air with a stone if (name.removeColor() == "Stone") continue diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/OdgerWaypoint.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/OdgerWaypoint.kt index bdd085ac1..d26ec6b90 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/OdgerWaypoint.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/OdgerWaypoint.kt @@ -5,10 +5,10 @@ import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.features.fishing.FishingAPI.isFishingRod import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.LorenzVec @@ -37,8 +37,7 @@ class OdgerWaypoint { private fun isLavaFishingRod(): Boolean { val heldItem = InventoryUtils.getItemInHand() ?: return false - val isRod = heldItem.name?.contains("Rod") ?: return false - if (!isRod) return false + if (!heldItem.isFishingRod()) return false return heldItem.getLore().any { it.contains("Lava Rod") } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt index 9ec66e9f8..c1df32a98 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt @@ -6,7 +6,6 @@ import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI import at.hannibal2.skyhanni.test.command.ErrorManager -import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils @@ -14,11 +13,9 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName -import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems @@ -64,9 +61,9 @@ class AnitaMedalProfit { readItem(item, table) } catch (e: Throwable) { ErrorManager.logErrorWithData( - e, "Error in AnitaMedalProfit while reading item '${item.nameWithEnchantment}'", + e, "Error in AnitaMedalProfit while reading item '${item.itemName}'", "item" to item, - "name" to item.nameWithEnchantment, + "name" to item.itemName, "inventory name" to InventoryUtils.openInventoryName(), ) } @@ -90,7 +87,7 @@ class AnitaMedalProfit { val (name, amount) = ItemUtils.readItemAmount(itemName) ?: return - var internalName = NEUItems.getInternalNameOrNull(name) + var internalName = NEUInternalName.fromItemNameOrNull(name) if (internalName == null) { internalName = item.getInternalName() } @@ -105,7 +102,7 @@ class AnitaMedalProfit { } private fun getItemName(item: ItemStack): String? { - val name = item.name ?: return null + val name = item.name val isEnchantedBook = name.removeColor() == "Enchanted Book" return if (isEnchantedBook) { item.itemName @@ -118,7 +115,10 @@ class AnitaMedalProfit { for (rawItemName in requiredItems) { val pair = ItemUtils.readItemAmount(rawItemName) if (pair == null) { - ChatUtils.error("Could not read item '$rawItemName'") + ErrorManager.logErrorStateWithData( + "Error in Anita Medal Contest", "Could not read item amount", + "rawItemName" to rawItemName, + ) continue } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt index d69b92bb3..766bdd55d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt @@ -9,7 +9,8 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -80,16 +81,16 @@ class GardenLevelDisplay { if (event.inventoryName != "Desk") return val item = event.inventoryItems[4]!! - val currentLevel = currentLevelPattern.matchMatcher(item.name!!.removeColor()) { + val currentLevel = currentLevelPattern.matchMatcher(item.name.removeColor()) { group("currentLevel").romanToDecimalIfNecessary() } ?: return var nextLevelExp = 0L for (line in item.getLore()) { expToNextLevelPattern.matchMatcher(line) { - nextLevelExp = group("nextLevelExp").formatNumber() + nextLevelExp = group("nextLevelExp").formatLong() } overflowPattern.matchMatcher(line) { - val overflow = group("overflow").formatNumber() + val overflow = group("overflow").formatLong() GardenAPI.gardenExp = overflow update() return @@ -115,9 +116,7 @@ class GardenLevelDisplay { val overflow = gardenExp - needForLevel val needForOnlyNextLvl = needForNextLevel - needForLevel - val need = LorenzUtils.formatInteger(overflow) - val have = LorenzUtils.formatInteger(needForOnlyNextLvl) - " §7(§e$need§7/§e$have§7)" + " §7(§e${overflow.addSeparators()}§7/§e${needForOnlyNextLvl.addSeparators()}§7)" } else "" } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt index 76e1395ab..22eabf10e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -185,8 +185,7 @@ object GardenNextJacobContest { if (!config.display) return val backItem = event.inventoryItems[48] ?: return - val backName = backItem.name - if (backName != "§aGo Back") return + if (backItem.name != "§aGo Back") return val lore = backItem.getLore() if (lore.size != 1) return if (lore[0] != "§7To Calendar and Events") return @@ -227,8 +226,7 @@ object GardenNextJacobContest { val lore = item.getLore() if (!lore.any { it.contains("§6§eJacob's Farming Contest") }) continue - val name = item.name ?: continue - val day = dayPattern.matchMatcher(name) { group("day").toInt() } ?: continue + val day = dayPattern.matchMatcher(item.name) { group("day").toInt() } ?: continue val startTime = SkyBlockTime(year, month, day).asTimeMark() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt index 085095f4f..a00440667 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt @@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.garden.composter import at.hannibal2.skyhanni.data.model.ComposterUpgrade import at.hannibal2.skyhanni.features.garden.GardenAPI -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils import kotlin.math.floor @@ -52,9 +52,9 @@ object ComposterAPI { return timePerCompost * compostRemainingAfterNextCompostFinishes } - fun getFuel() = tabListData[ComposterDisplay.DataType.FUEL]?.removeColor()?.formatNumber() ?: 0 + fun getFuel() = tabListData[ComposterDisplay.DataType.FUEL]?.removeColor()?.formatLong() ?: 0 - fun getOrganicMatter() = tabListData[ComposterDisplay.DataType.ORGANIC_MATTER]?.removeColor()?.formatNumber() ?: 0 + fun getOrganicMatter() = tabListData[ComposterDisplay.DataType.ORGANIC_MATTER]?.removeColor()?.formatLong() ?: 0 fun maxOrganicMatter(addOne: ComposterUpgrade?) = 40_000 + ComposterUpgrade.ORGANIC_MATTER_CAP.getLevel(addOne) * 20_000 diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt index c7a6b8f8b..349d20779 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt @@ -45,6 +45,8 @@ class ComposterDisplay { } } + private val BUCKET by lazy { "BUCKET".asInternalName().getItemStack() } + @SubscribeEvent fun onTabListUpdate(event: TabListUpdateEvent) { if (!(config.displayEnabled && GardenAPI.inGarden())) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt index acb62abe2..5747032cf 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -38,7 +39,7 @@ class ComposterInventoryNumbers { if (slotNumber == 13) { for (line in stack.getLore()) { amountPattern.matchMatcher(line) { - val total = group("amount").replace(",", "").toInt() + val total = group("amount").formatInt() event.offsetY = -2 event.offsetX = -20 event.stackTip = "§6${total.addSeparators()}" @@ -51,7 +52,7 @@ class ComposterInventoryNumbers { if (slotNumber == 46 || slotNumber == 52) { for (line in stack.getLore()) { valuePattern.matchMatcher(line) { - val having = group("having").removeColor().replace(",", "").toDouble().toInt() + val having = group("having").removeColor().formatInt() val havingFormat = NumberUtil.format(having) val total = group("total").removeColor() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt index 5a8b866e7..a34c7e8c0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt @@ -47,6 +47,7 @@ import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils +import at.hannibal2.skyhanni.utils.TimeUtils.format import at.hannibal2.skyhanni.utils.renderables.Renderable import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -105,6 +106,8 @@ object ComposterOverlay { ChatUtils.chat("Composter test offset set to $testOffset.") } + private val COMPOST by lazy { "COMPOST".asInternalName() } + @SubscribeEvent fun onInventoryClose(event: InventoryCloseEvent) { inInventory = false @@ -143,15 +146,14 @@ object ComposterOverlay { if (!inComposterUpgrades) return update() for (upgrade in ComposterUpgrade.entries) { - event.itemStack.name?.let { - if (it.contains(upgrade.displayName)) { - maxLevel = ComposterUpgrade.regex.matchMatcher(it) { - group("level")?.romanToDecimalIfNecessary() ?: 0 - } == 25 - extraComposterUpgrade = upgrade - update() - return - } + val name = event.itemStack.name + if (name.contains(upgrade.displayName)) { + maxLevel = ComposterUpgrade.regex.matchMatcher(name) { + group("level")?.romanToDecimalIfNecessary() ?: 0 + } == 25 + extraComposterUpgrade = upgrade + update() + return } } if (extraComposterUpgrade != null) { @@ -249,8 +251,7 @@ object ComposterOverlay { return newList } - private fun formatTime(timePerCompost1: Duration) = - TimeUtils.formatDuration(timePerCompost1.toLong(DurationUnit.MILLISECONDS), maxUnits = 2) + private fun formatTime(duration: Duration) = duration.format(maxUnits = 2) private fun drawOrganicMatterDisplay(): MutableList<List<Any>> { val maxOrganicMatter = ComposterAPI.maxOrganicMatter(if (maxLevel) null else extraComposterUpgrade) @@ -367,7 +368,7 @@ object ComposterOverlay { " §7Material costs per $timeText: §6${NumberUtil.format(totalCost)}$materialCostFormatPreview" newList.addAsSingletonList(materialCostFormat) - val priceCompost = getPrice("COMPOST") + val priceCompost = COMPOST.getPrice() val profit = ((priceCompost * multiDropFactor) - (fuelPricePer + organicMatterPricePer)) * timeMultiplier val profitPreview = ((priceCompost * multiDropFactorPreview) - (fuelPricePerPreview + organicMatterPricePerPreview)) * timeMultiplierPreview @@ -392,7 +393,7 @@ object ComposterOverlay { } val testOffset = if (testOffset_ > map.size) { - ChatUtils.error("Invalid Composter Overlay Offset! $testOffset cannot be greater than ${map.size}!") + ChatUtils.userError("Invalid Composter Overlay Offset! $testOffset cannot be greater than ${map.size}!") ComposterOverlay.testOffset = 0 0 } else testOffset_ @@ -425,7 +426,6 @@ object ComposterOverlay { val factor = factors[internalName]!! val item = internalName.getItemStack() - val itemName = item.name!! val price = getPrice(internalName) val itemsNeeded = if (config.roundDown) { val amount = missing / factor @@ -444,7 +444,7 @@ object ComposterOverlay { list.add("#$i ") } list.add(item) - formatPrice(totalPrice, internalName, itemName, list, itemsNeeded, onClick) + formatPrice(totalPrice, internalName, item.name, list, itemsNeeded, onClick) bigList.add(list) if (i == 10 + testOffset) break } @@ -571,13 +571,13 @@ object ComposterOverlay { || internalName == "SIMPLE_CARROT_CANDY" ) continue - var (newId, amount) = NEUItems.getMultiplier(internalName) + var (newId, amount) = NEUItems.getMultiplier(internalName.asInternalName()) if (amount <= 9) continue if (internalName == "ENCHANTED_HUGE_MUSHROOM_1" || internalName == "ENCHANTED_HUGE_MUSHROOM_2") { // 160 * 8 * 4 is 5120 and not 5184, but hypixel made an error, so we have to copy the error amount = 5184 } - baseValues[newId.asInternalName()]?.let { + baseValues[newId]?.let { map[internalName.asInternalName()] = it * amount } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt index 727c86ef0..399967809 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt @@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -132,7 +133,7 @@ object FarmingContestAPI { for (bracket in ContestBracket.entries) { val amount = lore.firstNotNullOfOrNull { bracket.bracketPattern.matchMatcher(it) { - group("amount").replace(",", "").toInt() + group("amount").formatInt() } } ?: continue put(bracket, amount) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt index da38c318b..b663690f0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt @@ -39,8 +39,7 @@ class JacobContestFFNeededDisplay { return } - val name = stack.name ?: return - val time = FarmingContestAPI.getSbTimeFor(name) ?: return + val time = FarmingContestAPI.getSbTimeFor(stack.name) ?: return val contest = FarmingContestAPI.getContestAtTime(time) ?: return val newDisplay = drawDisplay(contest) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt index 727aae614..f7576abba 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt @@ -55,10 +55,8 @@ class JacobFarmingContestsInventory { for ((slot, item) in event.inventoryItems) { if (!item.getLore().any { it.startsWith("§7Your score: §e") }) continue - val name = item.name!! - - foundEvents.add(name) - val time = FarmingContestAPI.getSbTimeFor(name) ?: continue + foundEvents.add(item.name) + val time = FarmingContestAPI.getSbTimeFor(item.name) ?: continue FarmingContestAPI.addContest(time, item) if (config.realTime) { readRealTime(time, slot) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt index ba9638711..31db0b811 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt @@ -58,6 +58,8 @@ object CropMoneyDisplay { private val cropNames = mutableMapOf<NEUInternalName, CropType>() private val toolHasBountiful get() = GardenAPI.storage?.toolWithBountiful + val BOX_OF_SEEDS by lazy { "BOX_OF_SEEDS".asInternalName().getItemStack() } + @SubscribeEvent fun onProfileJoin(event: ProfileJoinEvent) { display = emptyList() @@ -142,12 +144,17 @@ object CropMoneyDisplay { extraMushroomCowPerkCoins = perSecond * 60 * 60 } - if (InventoryUtils.getItemInHand()?.getInternalName()?.contains("DICER") == true && config.dicer) { + val itemInHand = InventoryUtils.getItemInHand()?.getInternalName() + if (itemInHand?.contains("DICER") == true && config.dicer) { val (dicerDrops, internalName) = when (it) { CropType.MELON -> GardenCropSpeed.latestMelonDicer to "ENCHANTED_MELON".asInternalName() CropType.PUMPKIN -> GardenCropSpeed.latestPumpkinDicer to "ENCHANTED_PUMPKIN".asInternalName() - else -> ErrorManager.skyHanniError("Unknown dicer: $it") + else -> ErrorManager.skyHanniError( + "Unknown dicer detected.", + "crop" to it, + "item in hand" to itemInHand, + ) } val bazaarData = internalName.getBazaarData() val price = @@ -195,13 +202,13 @@ object CropMoneyDisplay { try { if (isSeeds(internalName)) { - list.add(getItemStack("BOX_OF_SEEDS")) + list.add(BOX_OF_SEEDS) } else { list.add(internalName.getItemStack()) } if (cropNames[internalName] == CropType.WHEAT && config.mergeSeeds) { - list.add(getItemStack("BOX_OF_SEEDS")) + list.add(BOX_OF_SEEDS) } } catch (e: NullPointerException) { ErrorManager.logErrorWithData( @@ -274,7 +281,7 @@ object CropMoneyDisplay { private fun format(moneyPerHour: Double) = if (config.compactPrice) { NumberUtil.format(moneyPerHour) } else { - LorenzUtils.formatInteger(moneyPerHour.toLong()) + moneyPerHour.toLong().addSeparators() } private fun calculateMoneyPerHour(debugList: MutableList<List<Any>>): Map<NEUInternalName, Array<Double>> { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropTracker.kt index 592705bb7..b62eeb56b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropTracker.kt @@ -128,7 +128,7 @@ object DicerRngDropTracker { val crop = event.crop cropInHand = if (crop == CropType.MELON || crop == CropType.PUMPKIN) crop else null if (cropInHand != null) { - toolName = event.toolItem!!.name!! + toolName = event.toolItem!!.name } tracker.update() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt index a1181b1d0..abd29aee6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt @@ -37,7 +37,7 @@ class WildStrawberryDyeNotification { val internalName = itemStack.getInternalName() if (internalName == item) { - val name = itemStack.name!! + val name = itemStack.name LorenzUtils.sendTitle(name, 5.seconds) ChatUtils.chat("You found a $name§e!") SoundUtils.playBeepSound() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt index 9cbce06de..c5f6da249 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt @@ -65,7 +65,7 @@ open class FFGuideGUI : GuiScreen() { ItemStack(Blocks.barrier).setStackDisplayName(name) } - fun isFallbackItem(item: ItemStack) = item.name!!.startsWith("§cNo saved ") + fun isFallbackItem(item: ItemStack) = item.name.startsWith("§cNo saved ") } init { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/AnitaExtraFarmingFortune.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/AnitaExtraFarmingFortune.kt index 1ebc5be3b..27518b7d3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/AnitaExtraFarmingFortune.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/AnitaExtraFarmingFortune.kt @@ -12,7 +12,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -42,7 +42,7 @@ class AnitaExtraFarmingFortune { val baseAmount = levelPrice[anitaUpgrade + 1]?.jacob_tickets ?: return for (line in event.toolTip) { realAmountPattern.matchMatcher(line) { - val realAmount = group("realAmount").formatNumber().toDouble() + val realAmount = group("realAmount").formatDouble() contributionFactor = realAmount / baseAmount } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt index 98e2ffb41..5d76e6c57 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt @@ -49,11 +49,9 @@ class GardenInventoryNumbers { if (InventoryUtils.openInventoryName() == "Composter Upgrades") { if (!config.composterUpgrades) return - event.stack.name?.let { - ComposterUpgrade.regex.matchMatcher(it) { - val level = group("level")?.romanToDecimalIfNecessary() ?: 0 - event.stackTip = "$level" - } + ComposterUpgrade.regex.matchMatcher(event.stack.name) { + val level = group("level")?.romanToDecimalIfNecessary() ?: 0 + event.stackTip = "$level" } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt index 91c65b8a8..54414d211 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt @@ -2,11 +2,12 @@ package at.hannibal2.skyhanni.features.garden.inventory import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.features.garden.GardenAPI -import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -19,8 +20,7 @@ class GardenNextPlotPrice { if (InventoryUtils.openInventoryName() != "Configure Plots") return - val name = event.itemStack.name ?: return - if (!name.startsWith("§ePlot")) return + if (!event.itemStack.name.startsWith("§ePlot")) return var next = false val list = event.toolTip @@ -36,12 +36,17 @@ class GardenNextPlotPrice { val readItemAmount = ItemUtils.readItemAmount(line) readItemAmount?.let { val (itemName, amount) = it - val lowestBin = NEUItems.getPrice(NEUItems.getRawInternalName(itemName)) + val lowestBin = NEUInternalName.fromItemName(itemName).getPrice() val price = lowestBin * amount val format = NumberUtil.format(price) list[i] = list[i] + " §7(§6$format§7)" - } ?: { - ChatUtils.error("Could not read item '$line'") + } ?: run { + ErrorManager.logErrorStateWithData( + "Garden Next Plot Price error", + "Could not read item amount from line", + "line" to line, + "event.toolTip" to event.toolTip, + ) } break } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt index 81d01f2dd..d27401e44 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt @@ -8,13 +8,13 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -48,7 +48,7 @@ class SkyMartCopperPrice { if (!found) continue if (lines.isEmpty()) return list - NEUItems.getInternalNameOrNull(lines)?.let { + NEUInternalName.fromItemNameOrNull(lines)?.let { list.add(it) } } @@ -72,14 +72,14 @@ class SkyMartCopperPrice { val profit = lowestBin - otherItemsPrice val amount = copperPattern.matchMatcher(line) { - group("amount").replace(",", "").toInt() + group("amount").formatInt() } ?: continue val factor = profit / amount val perFormat = NumberUtil.format(factor) val priceFormat = NumberUtil.format(profit) val amountFormat = NumberUtil.format(amount) - val name = stack.nameWithEnchantment!! + val name = stack.itemName val advancedStats = if (config.copperPriceAdvancedStats) { " §7(§6$priceFormat §7/ §c$amountFormat Copper§7)" } else "" diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 38595d1bc..11669cece 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -46,6 +46,7 @@ import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -251,12 +252,7 @@ class GardenVisitorFeatures { list.add("§7(§fAny§7)") } else { for (item in items) { - val internalName = NEUItems.getInternalNameOrNull(item) - if (internalName != null) { - list.add(internalName.getItemStack()) - } else { - list.add(" '$item' ") - } + list.add(NEUInternalName.fromItemName(item).getItemStack()) } } } @@ -337,7 +333,7 @@ class GardenVisitorFeatures { } val (itemName, amount) = ItemUtils.readItemAmount(formattedLine) ?: continue - val internalName = NEUItems.getInternalNameOrNull(itemName)?.replace("◆_", "") ?: continue + val internalName = NEUInternalName.fromItemNameOrNull(itemName)?.replace("◆_", "") ?: continue // Ignoring custom NEU items like copper if (internalName.startsWith("SKYBLOCK_")) continue @@ -374,14 +370,14 @@ class GardenVisitorFeatures { val index = i + offset if (config.inventory.experiencePrice) { gardenExperiencePattern.matchMatcher(formattedLine) { - val gardenExp = group("amount").replace(",", "").toInt() + val gardenExp = group("amount").formatInt() val pricePerCopper = NumberUtil.format((totalPrice / gardenExp).toInt()) finalList.set(index, "$formattedLine §7(§6$pricePerCopper §7per)") } } copperPattern.matchMatcher(formattedLine) { - val copper = group("amount").replace(",", "").toInt() + val copper = group("amount").formatInt() val pricePerCopper = NumberUtil.format((totalPrice / copper).toInt()) val timePerCopper = TimeUtils.formatDuration((farmingTimeRequired / copper) * 1000) var copperLine = formattedLine @@ -397,7 +393,7 @@ class GardenVisitorFeatures { } val (itemName, amount) = ItemUtils.readItemAmount(formattedLine) ?: continue - val internalName = NEUItems.getInternalNameOrNull(itemName)?.replace("◆_", "") ?: continue + val internalName = NEUInternalName.fromItemNameOrNull(itemName)?.replace("◆_", "") ?: continue // Ignoring custom NEU items like copper if (internalName.startsWith("SKYBLOCK_")) continue @@ -414,8 +410,7 @@ class GardenVisitorFeatures { val cropType = getByNameOrNull(rawName) ?: continue val cropAmount = multiplier.second.toLong() * amount - val formattedAmount = LorenzUtils.formatInteger(cropAmount) - val formattedName = "§e$formattedAmount§7x ${cropType.cropName} " + val formattedName = "§e${cropAmount.addSeparators()}§7x ${cropType.cropName} " val formattedSpeed = cropType.getSpeed()?.let { speed -> farmingTimeRequired = cropAmount / speed val duration = TimeUtils.formatDuration(farmingTimeRequired * 1000) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt index 304da0d75..dac868528 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt @@ -101,7 +101,7 @@ class VisitorListener { val visitorOffer = VisitorAPI.VisitorOffer(offerItem) - var name = npcItem.name ?: return + var name = npcItem.name if (name.length == name.removeColor().length + 4) { name = name.substring(2) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt index be7451090..3b8a709a5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt @@ -9,7 +9,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -53,7 +53,7 @@ class AuctionsHighlighter { if (config.highlightAuctionsUnderbid) { for (line in lore) { buyItNowPattern.matchMatcher(line) { - val coins = group("coins").formatNumber() + val coins = group("coins").formatLong() stack.getInternalNameOrNull()?.getPriceOrNull()?.let { if (coins > it) { slot highlight LorenzColor.GOLD diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt index 4db2bb8f6..fa3724bca 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt @@ -173,11 +173,10 @@ object ItemDisplayOverlayFeatures { if (COLLECTION_LEVEL.isSelected() && InventoryUtils.openInventoryName().endsWith(" Collections")) { if (lore.any { it.contains("Click to view!") }) { if (CollectionAPI.isCollectionTier0(lore)) return "0" - item.name?.let { - if (it.startsWith("§e")) { - val text = it.split(" ").last() - return "" + text.romanToDecimalIfNecessary() - } + val name = item.name + if (name.startsWith("§e")) { + val text = name.split(" ").last() + return "" + text.romanToDecimalIfNecessary() } } } @@ -208,14 +207,12 @@ object ItemDisplayOverlayFeatures { } if (DUNGEON_POTION_LEVEL.isSelected() && itemName.startsWith("Dungeon ") && itemName.contains(" Potion")) { - item.name?.let { - dungeonPotionPattern.matchMatcher(it.removeColor()) { - return when (val level = group("level").romanToDecimal()) { - in 1..2 -> "§f$level" - in 3..4 -> "§a$level" - in 5..6 -> "§9$level" - else -> "§5$level" - } + dungeonPotionPattern.matchMatcher(item.name.removeColor()) { + return when (val level = group("level").romanToDecimal()) { + in 1..2 -> "§f$level" + in 3..4 -> "§a$level" + in 5..6 -> "§9$level" + else -> "§5$level" } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt index 040e215b8..3b7df6da5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt @@ -33,7 +33,7 @@ class ItemStars { val stack = event.itemStack ?: return if (stack.stackSize != 1) return - val itemName = stack.name ?: return + val itemName = stack.name val stars = getStars(itemName) if (stars > 0) { @@ -61,7 +61,7 @@ class ItemStars { fun onRenderItemTip(event: RenderItemTipEvent) { if (!CRIMSON_ARMOR.isSelected()) return val stack = event.stack - val number = getCrimsonStars(stack.name ?: return) + val number = getCrimsonStars(stack.name) if (number != -1) { event.stackTip = number.toString() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt index bf036b9c0..5291797a4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt @@ -65,8 +65,7 @@ class QuickCraftFeatures { if (slot == null) continue if (inventoryType.ignoreSlot(slot.slotNumber)) continue val stack = slot.stack ?: continue - val name = stack.name ?: continue - if (name == "§cQuick Crafting Slot") continue + if (stack.name == "§cQuick Crafting Slot") continue if (needsQuickCraftConfirmation(stack)) { val color = LorenzColor.DARK_GRAY.addOpacity(180) stack.background = color.rgb diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt index 7a83e09cd..0173fdfc7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt @@ -25,8 +25,7 @@ class RngMeterInventory { val stack = event.stack if (config.floorName && chestName == "Catacombs RNG Meter") { - val name = stack.name ?: return - if (name.removeColor() == "RNG Meter") { + if (stack.name.removeColor() == "RNG Meter") { event.stackTip = stack.getLore()[0].between("(", ")") } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SkyblockGuideHighlightFeature.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SkyblockGuideHighlightFeature.kt index 6212bc665..204fc9dd9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SkyblockGuideHighlightFeature.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SkyblockGuideHighlightFeature.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name @@ -124,7 +125,7 @@ class SkyblockGuideHighlightFeature private constructor( for ((slot, item) in event.inventoryItems) { if (slot == 4) continue // Overview Item - val loreAndName = listOf(item.name ?: "") + item.getLore() + val loreAndName = listOf(item.name) + item.getLore() if (!current.conditionPattern.anyMatches(loreAndName)) continue missing.add(slot) } @@ -144,7 +145,7 @@ class SkyblockGuideHighlightFeature private constructor( private val openWikiOnClick: (GuiContainerEvent.SlotClickEvent) -> Unit = { event -> val internalName = event.item?.getInternalName() if (internalName != null) { - LorenzUtils.sendCommandToServer("wiki ${internalName.asString()}") + ChatUtils.sendCommandToServer("wiki ${internalName.asString()}") } } @@ -174,7 +175,7 @@ class SkyblockGuideHighlightFeature private constructor( "travel", "Core ➜ Fast Travels Unlocked", taskOnlyCompleteOncePattern, - { LorenzUtils.sendCommandToServer("wiki MUSEUM_TRAVEL_SCROLL") }, // The items do not have proper internal names and using the fact that all travel scrolls lead to the same wiki page + { ChatUtils.sendCommandToServer("wiki MUSEUM_TRAVEL_SCROLL") }, // The items do not have proper internal names and using the fact that all travel scrolls lead to the same wiki page openWikiTooltip ) SkyblockGuideHighlightFeature( diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt index bc31e61e4..208be373d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt @@ -37,8 +37,7 @@ class StatsTuning { } private fun templateStats(stack: ItemStack, event: RenderInventoryItemTipEvent): Boolean { - val name = stack.name ?: return true - if (name != "§aLoad") return false + if (stack.name != "§aLoad") return false var grab = false val list = mutableListOf<String>() @@ -66,8 +65,7 @@ class StatsTuning { } private fun selectedStats(stack: ItemStack, event: RenderInventoryItemTipEvent): Boolean { - val name = stack.name ?: return true - if (name != "§aStats Tuning") return false + if (stack.name != "§aStats Tuning") return false var grab = false val list = mutableListOf<String>() diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarApi.kt index 2d8aebe1a..c771f7d42 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarApi.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarApi.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore @@ -38,12 +39,17 @@ class BazaarApi { var currentlyOpenedProduct: NEUInternalName? = null - fun getBazaarDataByName(name: String): BazaarData? = NEUItems.getInternalNameOrNull(name)?.getBazaarData() - fun NEUInternalName.getBazaarData() = if (isBazaarItem()) { holder.getData(this) } else null + fun NEUInternalName.getBazaarDataOrError(): BazaarData = getBazaarData() ?: run { + ErrorManager.skyHanniError( + "Can not find bazaar data for internal name", + "internal name" to this + ) + } + fun isBazaarItem(stack: ItemStack): Boolean = stack.getInternalName().isBazaarItem() fun NEUInternalName.isBazaarItem() = NEUItems.manager.auctionManager.getBazaarInfo(asString()) != null @@ -63,20 +69,19 @@ class BazaarApi { fun onInventoryOpen(event: InventoryFullyOpenedEvent) { inBazaarInventory = checkIfInBazaar(event) if (inBazaarInventory) { - val itemName = getOpenedProduct(event.inventoryItems) ?: return - val openedProduct = NEUItems.getInternalNameOrNull(itemName) + val openedProduct = getOpenedProduct(event.inventoryItems) ?: return currentlyOpenedProduct = openedProduct BazaarOpenedProductEvent(openedProduct, event).postAndCatch() } } - private fun getOpenedProduct(inventoryItems: Map<Int, ItemStack>): String? { + private fun getOpenedProduct(inventoryItems: Map<Int, ItemStack>): NEUInternalName? { val buyInstantly = inventoryItems[10] ?: return null if (buyInstantly.displayName != "§aBuy Instantly") return null val bazaarItem = inventoryItems[13] ?: return null - return bazaarItem.displayName + return NEUInternalName.fromItemName(bazaarItem.displayName) } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt index 9391e09db..90002a548 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt @@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.features.inventory.bazaar import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.BazaarOpenedProductEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent -import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.Companion.getBazaarData +import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.Companion.getBazaarDataOrError import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.itemName @@ -56,7 +56,7 @@ class BazaarBestSellMethod { } if (having <= 0) return "" - val data = internalName.getBazaarData() ?: return "" + val data = internalName.getBazaarDataOrError() val totalDiff = (data.buyPrice - data.sellPrice) * having val result = NumberUtil.format(totalDiff.toInt()) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt index e0487ecb5..9a02fb1df 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt @@ -32,8 +32,7 @@ class BazaarCancelledBuyOrderClipboard { if (!isEnabled()) return val stack = event.itemStack - val name = stack.name ?: return - if (!name.contains("Cancel Order")) return + if (!stack.name.contains("Cancel Order")) return for (line in stack.getLore()) { lastAmountPattern.findMatcher(line) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarDataHolder.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarDataHolder.kt index 7061b7e63..3115caadb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarDataHolder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarDataHolder.kt @@ -67,7 +67,7 @@ class BazaarDataHolder { ChatUtils.debug("Bazaar data is null: '$internalName'") return null } - val displayName = stack.name!!.removeColor() + val displayName = stack.name.removeColor() val sellPrice = internalName.getPrice(true) val buyPrice = internalName.getPrice(false) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt index cb9bf31bc..218345ec6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt @@ -2,7 +2,8 @@ package at.hannibal2.skyhanni.features.inventory.bazaar import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent @@ -19,7 +20,7 @@ class BazaarOpenPriceWebsite { private var lastClick = SimpleTimeMark.farPast() private val item by lazy { - val neuItem = NEUItems.getItemStack("PAPER") + val neuItem = "PAPER".asInternalName().getItemStack() Utils.createItemStack( neuItem.item, "§bPrice History", diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOrderHelper.kt index 9e9d31f04..165e1a5a5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOrderHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOrderHelper.kt @@ -2,12 +2,14 @@ package at.hannibal2.skyhanni.features.inventory.bazaar import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.Companion.getBazaarDataOrError import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -56,8 +58,7 @@ class BazaarOrderHelper { if (slot.slotNumber != slot.slotIndex) continue if (slot.stack == null) continue - val itemName = slot.stack.name ?: continue - bazaarItemNamePattern.matchMatcher(itemName) { + bazaarItemNamePattern.matchMatcher(slot.stack.name) { val buyOrSell = group("type").let { (it == "BUY") to (it == "SELL") } if (buyOrSell.let { !it.first && !it.second }) return @@ -67,11 +68,7 @@ class BazaarOrderHelper { } private fun highlightItem(itemName: String, slot: Slot, buyOrSell: Pair<Boolean, Boolean>) { - val data = BazaarApi.getBazaarDataByName(itemName) - if (data == null) { - ChatUtils.debug("Bazaar data is null for bazaarItemName '$itemName'") - return - } + val data = NEUInternalName.fromItemName(itemName).getBazaarDataOrError() val itemLore = slot.stack.getLore() for (line in itemLore) { @@ -81,7 +78,7 @@ class BazaarOrderHelper { } pricePattern.matchMatcher(line) { - val price = group("number").replace(",", "").toDouble() + val price = group("number").formatDouble() if (buyOrSell.first && price < data.sellPrice || buyOrSell.second && price > data.buyPrice) { slot highlight LorenzColor.GOLD return diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/ChickenHeadTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/ChickenHeadTimer.kt index 6386ef478..643e15623 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/ChickenHeadTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/ChickenHeadTimer.kt @@ -10,28 +10,30 @@ import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import at.hannibal2.skyhanni.utils.TimeUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.TimeUtils.format import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds class ChickenHeadTimer { + private val config get() = SkyHanniMod.feature.itemAbilities.chickenHead private var hasChickenHead = false - private var lastTime = 0L - private val config get() = SkyHanniMod.feature.itemAbilities.chickenHead + private var lastTime = SimpleTimeMark.farPast() + private val cooldown = 5.seconds @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!isEnabled()) return if (!event.isMod(5)) return - val itemStack = InventoryUtils.getHelmet() - val name = itemStack?.name ?: "" + val name = InventoryUtils.getHelmet()?.name ?: "" hasChickenHead = name.contains("Chicken Head") } @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { - lastTime = System.currentTimeMillis() + lastTime = SimpleTimeMark.now() } @SubscribeEvent @@ -39,7 +41,7 @@ class ChickenHeadTimer { if (!isEnabled()) return if (!hasChickenHead) return if (event.message == "§aYou laid an egg!") { - lastTime = System.currentTimeMillis() + lastTime = SimpleTimeMark.now() if (config.hideChat) { event.blockedReason = "chicken_head_timer" } @@ -51,14 +53,11 @@ class ChickenHeadTimer { if (!isEnabled()) return if (!hasChickenHead) return - val sinceLastTime = System.currentTimeMillis() - lastTime - val cooldown = 5_000 - val remainingTime = cooldown - sinceLastTime - - val displayText = if (remainingTime < 0) { + val remainingTime = cooldown - lastTime.passedSince() + val displayText = if (remainingTime.isNegative()) { "Chicken Head Timer: §aNow" } else { - val formatDuration = TimeUtils.formatDuration(remainingTime) + val formatDuration = remainingTime.format() "Chicken Head Timer: §b$formatDuration" } diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt index 5f623359e..b908acefc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt @@ -29,9 +29,10 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LocationUtils.canBeSeen import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.formatInteger import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.RenderUtils.drawString @@ -251,13 +252,13 @@ class MinionFeatures { } ?: return "§cCan't calculate coins/day: No time data available!" //§7Held Coins: §b151,389 - val coins = line.split(": §b")[1].replace(",", "").toDouble() + // TODO use regex + val coins = line.split(": §b")[1].formatDouble() val coinsPerDay = (coins / (duration.toDouble())) * 1000 * 60 * 60 * 24 - val format = formatInteger(coinsPerDay.toInt()) - val hopperName = stack.name - return "§7Coins/day with $hopperName§7: §6$format coins" + val format = coinsPerDay.toInt().addSeparators() + return "§7Coins/day with ${stack.name}§7: §6$format coins" } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/BrewingStandOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/BrewingStandOverlay.kt index cbcb52db7..d4ed4f815 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/BrewingStandOverlay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/BrewingStandOverlay.kt @@ -16,7 +16,7 @@ class BrewingStandOverlay { if (event.inventoryName != "Brewing Stand") return val stack = event.stack - val name = stack.name ?: return + val name = stack.name val slotNumber = event.slot.slotNumber when (slotNumber) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt index 459bfc25a..2b749c3a6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt @@ -78,16 +78,16 @@ class CollectionTracker { val foundInternalName = NEUInternalName.fromItemNameOrNull(rawName) if (foundInternalName == null) { - ChatUtils.error("Item '$rawName' does not exist!") + ChatUtils.userError("Item '$rawName' does not exist!") return } val stack = foundInternalName.getItemStackOrNull() if (stack == null) { - ChatUtils.error("Item '$rawName' does not exist!") + ChatUtils.userError("Item '$rawName' does not exist!") return } - setNewCollection(foundInternalName, stack.name!!.removeColor()) + setNewCollection(foundInternalName, stack.name.removeColor()) } private fun fixTypo(rawName: String) = when (rawName) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt index daaf6c8be..d8069ae59 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt @@ -21,6 +21,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.TimeUnit import at.hannibal2.skyhanni.utils.TimeUtils +import at.hannibal2.skyhanni.utils.TimeUtils.format import at.hannibal2.skyhanni.utils.TimeUtils.timerColor import at.hannibal2.skyhanni.utils.Timer import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -28,7 +29,6 @@ import net.minecraft.network.play.server.S47PacketPlayerListHeaderFooter import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.hours -import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds @@ -154,7 +154,7 @@ class NonGodPotEffectDisplay { if (effect.isMixin && !config.nonGodPotEffectShowMixins) continue val remaining = time.remaining.coerceAtLeast(0.seconds) - val format = TimeUtils.formatDuration(remaining.inWholeMilliseconds, TimeUnit.HOUR) + val format = remaining.format(TimeUnit.HOUR) val color = remaining.timerColor() val displayName = effect.tabListName @@ -189,7 +189,7 @@ class NonGodPotEffectDisplay { if (!event.inventoryName.endsWith("Active Effects")) return for (stack in event.inventoryItems.values) { - val name = stack.name ?: continue + val name = stack.name for (effect in NonGodPotEffect.entries) { if (!name.contains(effect.inventoryItemName)) continue for (line in stack.getLore()) { @@ -198,7 +198,7 @@ class NonGodPotEffectDisplay { !line.contains("Remaining Uses") ) { val duration = try { - TimeUtils.getMillis(line.split("§f")[1]) + TimeUtils.getDuration(line.split("§f")[1]) } catch (e: IndexOutOfBoundsException) { ErrorManager.logErrorWithData( e, "Error while reading Non God-Potion effects from tab list", @@ -206,7 +206,7 @@ class NonGodPotEffectDisplay { ) continue } - effectDuration[effect] = Timer(duration.milliseconds) + effectDuration[effect] = Timer(duration) update() } } @@ -232,8 +232,8 @@ class NonGodPotEffectDisplay { if ("$line§r".startsWith(tabListName)) { val string = line.substring(tabListName.length) try { - val duration = TimeUtils.getMillis(string.split("§f")[1]) - effectDuration[effect] = Timer(duration.milliseconds) + val duration = TimeUtils.getDuration(string.split("§f")[1]) + effectDuration[effect] = Timer(duration) update() } catch (e: IndexOutOfBoundsException) { ChatUtils.debug("Error while reading non god pot effects from tab list! line: '$line'") diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt index e5611fb90..29a149830 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt @@ -35,7 +35,7 @@ class PetExpTooltip { val itemStack = event.itemStack ?: return val petExperience = itemStack.getPetExp()?.round(1) ?: return - val name = itemStack.name ?: return + val name = itemStack.name try { val index = findIndex(event.toolTip) ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt index bbe5dda74..71ee70b55 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt @@ -12,7 +12,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches @@ -68,7 +68,7 @@ class AuctionHouseCopyUnderbidPrice { for (line in lore) { auctionPricePattern.matchMatcher(line) { - val underbid = group("coins").formatNumber() - 1 + val underbid = group("coins").formatLong() - 1 OSUtils.copyToClipboard("$underbid") ChatUtils.chat("Copied ${underbid.addSeparators()} to clipboard.") return diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt index e5da89e83..9040abfe0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt @@ -178,7 +178,7 @@ object EstimatedItemValue { val internalName = stack.getInternalNameOrNull() ?: return listOf() // Stats Breakdown - val name = stack.name ?: return listOf() + val name = stack.name if (name == "§6☘ Category: Item Ability (Passive)") return listOf() if (name.contains("Salesperson")) return listOf() diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt index 3076ba439..d3b226744 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt @@ -37,11 +37,10 @@ class EstimatedWardrobePrice { var totalPrice = 0.0 for (item in items) { - val name = item.name val price = EstimatedItemValueCalculator.calculate(item, mutableListOf()).first totalPrice += price - toolTip.add(index++, " §7- $name: §6${NumberUtil.format(price)}") + toolTip.add(index++, " §7- ${item.name}: §6${NumberUtil.format(price)}") } toolTip.add(index, " §aTotal Value: §6§l${NumberUtil.format(totalPrice)} coins") } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/GlowingDroppedItems.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/GlowingDroppedItems.kt index 15d33fee7..b2b97c381 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/GlowingDroppedItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/GlowingDroppedItems.kt @@ -53,7 +53,7 @@ class GlowingDroppedItems { if (shouldHideShowcaseItem(entity)) return null val entityItem = item.entityItem - if (!config.highlightFishingBait && entityItem.name?.endsWith(" Bait") == true) { + if (!config.highlightFishingBait && entityItem.name.endsWith(" Bait")) { return null } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/teleportpad/TeleportPadInventoryNumber.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/teleportpad/TeleportPadInventoryNumber.kt index 92b47fc53..42450f72c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/teleportpad/TeleportPadInventoryNumber.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/teleportpad/TeleportPadInventoryNumber.kt @@ -78,11 +78,8 @@ class TeleportPadInventoryNumber { if (!IslandType.PRIVATE_ISLAND.isInIsland()) return if (!inTeleportPad) return - val name = event.stack.name?.lowercase() ?: return - - padNumberPattern.matchMatcher(name) { - val text = group("number") - numbers[text]?.let { + padNumberPattern.matchMatcher(event.stack.name.lowercase()) { + numbers[group("number")]?.let { event.stackTip = "$it" } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/PabloHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/PabloHelper.kt index 0e07441da..a65d5d030 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/PabloHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/PabloHelper.kt @@ -32,7 +32,7 @@ class PabloHelper { group("flower") } ?: return - if (InventoryUtils.countItemsInLowerInventory { it.name?.contains(itemName) == true } > 0) return + if (InventoryUtils.countItemsInLowerInventory { it.name.contains(itemName) } > 0) return ChatUtils.clickableChat("Click here to grab an $itemName from sacks!", "gfs $itemName 1") lastSentMessage = SimpleTimeMark.now() diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangHideParticles.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangHideParticles.kt index fc9ae54c8..7f15d294c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangHideParticles.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangHideParticles.kt @@ -41,7 +41,7 @@ class AshfangHideParticles { if (entity is EntityArmorStand) { for (stack in entity.inventory) { if (stack == null) continue - val name = stack.name ?: continue + val name = stack.name if (name == "§aFairy Souls") continue if (name == "Glowstone") { event.isCanceled = true diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt index 89ff65e5c..8042f6f5c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt @@ -40,6 +40,7 @@ import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import at.hannibal2.skyhanni.utils.StringUtils.removeWordsAtEnd import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -99,9 +100,8 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) { if (slot == null) continue if (slot.slotNumber != slot.slotIndex) continue val stack = slot.stack ?: continue - val itemName = stack.name ?: continue - if (itemName.contains(dojoQuest.dojoName)) { + if (stack.name.contains(dojoQuest.dojoName)) { slot highlight LorenzColor.AQUA } } @@ -143,7 +143,7 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) { val itemName = fetchQuest.itemName - val count = InventoryUtils.countItemsInLowerInventory { it.name?.contains(itemName) ?: false } + val count = InventoryUtils.countItemsInLowerInventory { it.name.contains(itemName) } updateProcessQuest(fetchQuest, count) } @@ -253,7 +253,7 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) { val displayName = if (category == QuestCategory.FETCH || category == QuestCategory.FISHING) { val name = item.name if (category == QuestCategory.FISHING) { - name!!.split(" ").dropLast(1).joinToString(" ") + name.removeWordsAtEnd(1) } else name } else quest.displayName diff --git a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt index 1ec2a08d5..9efac5974 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt @@ -20,6 +20,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils.chat import at.hannibal2.skyhanni.utils.ConditionalUtils.onToggle import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble import at.hannibal2.skyhanni.utils.NumberUtil.interpolate import at.hannibal2.skyhanni.utils.NumberUtil.roundToPrecision import at.hannibal2.skyhanni.utils.Quad @@ -457,8 +458,8 @@ object SkillProgress { if (config.showActionLeft.get() && percent != 100f) { append(" - ") - val gain = skill.lastGain.replace(",", "") - val actionLeft = (ceil(currentXpMax.toDouble() - currentXp) / gain.toDouble()).toLong().addSeparators() + val gain = skill.lastGain.formatDouble() + val actionLeft = (ceil(currentXpMax.toDouble() - currentXp) / gain).toLong().addSeparators() if (skill.lastGain != "" && !actionLeft.contains("-")) { append("§6$actionLeft Left") } else { diff --git a/src/main/java/at/hannibal2/skyhanni/test/TestCopyBestiaryValues.kt b/src/main/java/at/hannibal2/skyhanni/test/TestCopyBestiaryValues.kt index 348d05cb2..03a0776ce 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/TestCopyBestiaryValues.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/TestCopyBestiaryValues.kt @@ -8,10 +8,11 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.getSkullOwner import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.StringUtils.removeWordsAtEnd import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import com.google.gson.GsonBuilder import com.google.gson.annotations.Expose @@ -67,8 +68,7 @@ object TestCopyBestiaryValues { } private fun copy(titleItem: ItemStack, inventoryItems: Map<Int, ItemStack>) { - val name = titleItem.name ?: return - val titleName = name.split(" ").dropLast(1).joinToString(" ") + val titleName = titleItem.name.removeWordsAtEnd(1) val obj = BestiarityObject() obj.name = titleName @@ -82,14 +82,13 @@ object TestCopyBestiaryValues { return } val capLine = lore.nextAfter(overallProgress) ?: return - val rawCap = capLine.substringAfter("/").removeColor().formatNumber() - obj.cap = rawCap.toInt() + val rawCap = capLine.substringAfter("/").removeColor().formatInt() + obj.cap = rawCap val mobs = mutableListOf<String>() for (i in 10..43) { val stack = inventoryItems[i] ?: continue - val stackName = stack.name ?: continue - bestiaryTypePattern.matchMatcher(stackName.removeColor()) { + bestiaryTypePattern.matchMatcher(stack.name.removeColor()) { val lvl = group("lvl").toInt() var text = group("text").lowercase().replace(" ", "_") diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyBossbarCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyBossbarCommand.kt index cac3ac02f..3b29821fd 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyBossbarCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyBossbarCommand.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.test.command import at.hannibal2.skyhanni.data.BossbarData -import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -11,10 +11,10 @@ object CopyBossbarCommand { val bossbarName = if (noFormattingCodes) BossbarData.getBossbar().removeColor() else BossbarData.getBossbar() val status = if (noFormattingCodes) "without" else "with" if (bossbarName.isBlank()) { - LorenzUtils.chat("Boss bar appears to be blank.") + ChatUtils.chat("Boss bar appears to be blank.") } else { OSUtils.copyToClipboard(bossbarName) - LorenzUtils.chat("Boss bar name copied to clipboard $status formatting codes!") + ChatUtils.chat("Boss bar name copied to clipboard $status formatting codes!") } } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt index 4cd3a9bfd..bc1efc143 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt @@ -54,9 +54,9 @@ object ErrorManager { cache.clear() } - fun skyHanniError(message: String): Nothing { + fun skyHanniError(message: String, vararg extraData: Pair<String, Any?>): Nothing { val exception = IllegalStateException(message) - logErrorWithData(exception, message) + logErrorWithData(exception, message, extraData = extraData) throw exception } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt index fd1c4030b..7e35d02b1 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt @@ -121,7 +121,12 @@ object APIUtil { } val message = "POST request to '$urlString' returned status ${status.statusCode}" - ChatUtils.error("SkyHanni ran into an error. Status: ${status.statusCode}") + ErrorManager.logErrorStateWithData( + "Error communicating with API", "APIUtil POST request returned an error code", + "statusCode" to status.statusCode, + "urlString" to urlString, + "body" to body, + ) return ApiResponse(false, message, JsonObject()) } } catch (throwable: Throwable) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemCategory.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemCategory.kt index 975a409c3..4a16585f1 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemCategory.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemCategory.kt @@ -43,6 +43,7 @@ enum class ItemCategory { ITEM, PET_ITEM, ENCHANTED_BOOK, + FISHING_BAIT, POTION, RIFT_TIMECHARM, COSMETIC, diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 30e8adcee..196103e2d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.data.PetAPI import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.cachedData import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments @@ -203,7 +203,6 @@ object ItemUtils { fun ItemStack.getItemRarityOrCommon() = getItemRarityOrNull() ?: LorenzRarity.COMMON private fun ItemStack.readItemCategoryAndRarity(): Pair<LorenzRarity?, ItemCategory?> { - val name = this.name ?: "" val cleanName = this.cleanName() if (PetAPI.hasPetName(cleanName)) { @@ -250,6 +249,7 @@ object ItemUtils { if (itemCategory.isEmpty()) when { UtilsPatterns.abiPhonePattern.matches(name) -> ItemCategory.ABIPHONE PetAPI.hasPetName(cleanName) -> ItemCategory.PET + UtilsPatterns.baitPattern.matches(cleanName) -> ItemCategory.FISHING_BAIT UtilsPatterns.enchantedBookPattern.matches(name) -> ItemCategory.ENCHANTED_BOOK UtilsPatterns.potionPattern.matches(name) -> ItemCategory.POTION UtilsPatterns.sackPattern.matches(name) -> ItemCategory.SACK @@ -291,17 +291,24 @@ object ItemUtils { private fun itemRarityLastCheck(data: CachedItemData) = data.itemRarityLastCheck.asTimeMark().passedSince() > 10.seconds - // use when compaaring the name (e.g. regex), not for showing to the user - // extra method for shorter name and kotlin nullability logic - var ItemStack.name: String? - get() = this.displayName + /** + * Use when comparing the name (e.g. regex), not for showing to the user + * Member that provides the item name, is null save or throws visual error + */ + var ItemStack.name: String + get() = this.displayName ?: ErrorManager.skyHanniError( + "Could not get name if ItemStack", + "itemStack" to this, + "displayName" to displayName, + "internal name" to getInternalNameOrNull(), + ) set(value) { setStackDisplayName(value) } - @Deprecated("outdated", ReplaceWith("itemName")) + @Deprecated("outdated", ReplaceWith("this.itemName")) val ItemStack.nameWithEnchantment: String? - get() = getInternalNameOrNull()?.itemName + get() = itemName fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName()?.equals("SKYBLOCK_MENU") ?: false @@ -341,7 +348,7 @@ object ItemUtils { private fun makePair(input: String, itemName: String, matcher: Matcher): Pair<String, Int> { val matcherAmount = matcher.group("amount") - val amount = matcherAmount?.formatNumber()?.toInt() ?: 1 + val amount = matcherAmount?.formatInt() ?: 1 val pair = Pair(itemName, amount) itemAmountCache[input] = pair return pair diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 60a466b98..80fca6178 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -305,9 +305,6 @@ object LorenzUtils { TitleManager.sendTitle(text, duration, height, fontSize) } - @Deprecated("Dont use this approach at all. check with regex or equals instead.", ReplaceWith("Regex or equals")) - fun Iterable<String>.anyContains(element: String) = any { it.contains(element) } - inline fun <reified T : Enum<T>> enumValueOfOrNull(name: String): T? { val enums = enumValues<T>() return enums.firstOrNull { it.name == name } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 12acfb2ff..67f01b531 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -63,7 +63,7 @@ object NEUItems { allItemsCache = readAllNeuItems() } - @Deprecated("Use NEUInternalName rather than String", ReplaceWith("getInternalNameFromItemName()")) + @Deprecated("Use NEUInternalName rather than String", ReplaceWith("NEUInternalName.fromItemName(itemName)")) fun getRawInternalName(itemName: String): String = NEUInternalName.fromItemName(itemName).asString() fun readAllNeuItems(): Map<String, NEUInternalName> { @@ -111,7 +111,7 @@ object NEUItems { if (result != -1.0) return result if (equals("JACK_O_LANTERN")) { - return getPrice("PUMPKIN", useSellingPrice) + 1 + return "PUMPKIN".asInternalName().getPrice(useSellingPrice) + 1 } if (equals("GOLDEN_CARROT")) { // 6.8 for some players @@ -131,7 +131,7 @@ object NEUItems { fun getItemStackOrNull(internalName: String) = internalName.asInternalName().getItemStackOrNull() // TODO remove - @Deprecated("Use NEUInternalName rather than String", ReplaceWith("getItemStack()")) + @Deprecated("Use NEUInternalName rather than String", ReplaceWith("internalName.asInternalName().getItemStack()")) fun getItemStack(internalName: String): ItemStack = internalName.asInternalName().getItemStack() @@ -268,7 +268,7 @@ object NEUItems { return result } - @Deprecated("Do not use strings as id", ReplaceWith("getMultiplier with NEUInternalName")) + @Deprecated("Do not use strings as id", ReplaceWith("NEUItems.getMultiplier(internalName.asInternalName())")) fun getMultiplier(internalName: String, tryCount: Int = 0): Pair<String, Int> { val pair = getMultiplier(internalName.asInternalName(), tryCount) return Pair(pair.first.asString(), pair.second) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt index 728a9f4ba..621f2fd5e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt @@ -39,6 +39,7 @@ value class SimpleTimeMark(private val millis: Long) : Comparable<SimpleTimeMark fun now() = SimpleTimeMark(System.currentTimeMillis()) fun farPast() = SimpleTimeMark(0) + fun farFuture() = SimpleTimeMark(Long.MAX_VALUE) fun Long.asTimeMark() = SimpleTimeMark(this) fun SkyBlockTime.asTimeMark() = SimpleTimeMark(toMillis()) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt index 6ca2dd629..ebc0313c7 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt @@ -154,7 +154,7 @@ object SkyBlockItemModifierUtils { fun ItemStack.getReforgeName() = getAttributeString("modifier")?.let { when { it == "pitchin" -> "pitchin_koi" - it == "warped" && name!!.removeColor().startsWith("Hyper ") -> "endstone_geode" + it == "warped" && name.removeColor().startsWith("Hyper ") -> "endstone_geode" else -> it } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt index df34ec70e..d2b269e9a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt @@ -30,7 +30,10 @@ object TimeUtils { else -> default } - @Deprecated("Has an offset of one second", ReplaceWith("use kotlin Duration")) + @Deprecated( + "Has an offset of one second", + ReplaceWith("millis.toDuration(DurationUnit.MILLISECONDS).format(biggestUnit, showMilliSeconds, longName, maxUnits)") + ) fun formatDuration( millis: Long, biggestUnit: TimeUnit = TimeUnit.YEAR, @@ -78,7 +81,7 @@ object TimeUtils { return builder.toString().trim() } - @Deprecated("Do no longer use long for time", ReplaceWith("getDuration(string)")) + @Deprecated("Do no longer use long for time", ReplaceWith("TimeUtils.getDuration(string)")) fun getMillis(string: String) = getDuration(string).inWholeMilliseconds fun getDuration(string: String) = getMillis_(string.replace("m", "m ").replace(" ", " ").trim()) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt b/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt index ae7c24783..42ff1a06d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt @@ -32,6 +32,12 @@ object UtilsPatterns { "item.name.enchanted.book", ".{2}?Enchanted Book" ) + + val baitPattern by patternGroup.pattern( + "item.name.bait", + "^(Obfuscated.*|.* Bait)$" + ) + val enchantmentNamePattern by patternGroup.pattern( "item.neuitems.enchantmentname", "^(?<format>(?:§.)+)(?<name>[^§]+) (?<level>[IVXL]+)$" |