diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-02 16:27:10 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-02 16:27:10 +0100 |
commit | b1a5ab4e07b2ad0700abd26fc46b2d68cf9c4a81 (patch) | |
tree | 219eccb64384de98f7cab9d63ee2bc8e8c1381f8 | |
parent | 0c510cb4e246897d53b98589ffe3f690127df625 (diff) | |
download | skyhanni-b1a5ab4e07b2ad0700abd26fc46b2d68cf9c4a81.tar.gz skyhanni-b1a5ab4e07b2ad0700abd26fc46b2d68cf9c4a81.tar.bz2 skyhanni-b1a5ab4e07b2ad0700abd26fc46b2d68cf9c4a81.zip |
code cleanup.
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt | 121 |
1 files changed, 57 insertions, 64 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt index 42d58ea8a..e756590c3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt @@ -134,80 +134,73 @@ class GardenVisitorFeatures { val name = event.itemStack.name ?: return if (name != "§aAccept Offer") return - // TODO remove - try { - val list = event.toolTip - var totalPrice = 0.0 - var amountItems = 0 - var endReached = false - for ((i, l) in list.toMutableList().withIndex()) { - val line = l.substring(4) - if (line == "") { - if (config.visitorShowPrice) { - if (amountItems > 1) { - val format = NumberUtil.format(totalPrice) - list[1] = list[1] + "$line §f(§6Total §6$format§f)" - } + val list = event.toolTip + var totalPrice = 0.0 + var amountItems = 0 + var endReached = false + for ((i, l) in list.toMutableList().withIndex()) { + val line = l.substring(4) + if (line == "") { + if (config.visitorShowPrice) { + if (amountItems > 1) { + val format = NumberUtil.format(totalPrice) + list[1] = list[1] + "$line §f(§6Total §6$format§f)" } - endReached = true } + endReached = true + } - // Items Required - if (i > 1 && !endReached) { - val (itemName, amount) = ItemUtils.readItemAmount(line) - if (itemName != null) { - val internalName: String - try { - internalName = NEUItems.getInternalName(itemName) - } catch (e: NullPointerException) { - val message = "internal name is null: '$itemName'" - println(message) - LorenzUtils.error(message) - e.printStackTrace() - return - } - if (config.visitorShowPrice) { - val price = NEUItems.getPrice(internalName) * amount - totalPrice += price - val format = NumberUtil.format(price) - list[i] = "$line §7(§6$format§7)" - } - amountItems++ - - if (config.visitorExactAmountAndTime) { - val multiplier = NEUItems.getMultiplier(internalName) - val rawName = NEUItems.getItemStack(multiplier.first).name ?: continue - val crop = rawName.removeColor() - val cropAmount = multiplier.second.toLong() * amount - GardenCropMilestoneDisplay.cropsPerSecond[crop]?.let { - val formatAmount = LorenzUtils.formatInteger(cropAmount) - val formatName = "§e${formatAmount}§7x $crop " - val formatSpeed = if (it != -1) { - val missingTimeSeconds = cropAmount / it - val duration = TimeUtils.formatDuration(missingTimeSeconds * 1000) - "in §b$duration" - } else { - "§cno speed data!" - } - list.add(i + amountItems, " §7- $formatName($formatSpeed§7)") + // Items Required + if (i > 1 && !endReached) { + val (itemName, amount) = ItemUtils.readItemAmount(line) + if (itemName != null) { + val internalName: String + try { + internalName = NEUItems.getInternalName(itemName) + } catch (e: NullPointerException) { + val message = "internal name is null: '$itemName'" + println(message) + LorenzUtils.error(message) + e.printStackTrace() + return + } + if (config.visitorShowPrice) { + val price = NEUItems.getPrice(internalName) * amount + totalPrice += price + val format = NumberUtil.format(price) + list[i] = "$line §7(§6$format§7)" + } + amountItems++ + + if (config.visitorExactAmountAndTime) { + val multiplier = NEUItems.getMultiplier(internalName) + val rawName = NEUItems.getItemStack(multiplier.first).name ?: continue + val crop = rawName.removeColor() + val cropAmount = multiplier.second.toLong() * amount + GardenCropMilestoneDisplay.cropsPerSecond[crop]?.let { + val formatAmount = LorenzUtils.formatInteger(cropAmount) + val formatName = "§e${formatAmount}§7x $crop " + val formatSpeed = if (it != -1) { + val missingTimeSeconds = cropAmount / it + val duration = TimeUtils.formatDuration(missingTimeSeconds * 1000) + "in §b$duration" + } else { + "§cno speed data!" } + list.add(i + amountItems, " §7- $formatName($formatSpeed§7)") } } } + } - if (config.visitorCopperPrice) { - val matcher = copperPattern.matcher(line) - if (matcher.matches()) { - val coppers = matcher.group(1).replace(",", "").toInt() - val pricePerCopper = NumberUtil.format((totalPrice / coppers).toInt()) - list[i] = list[i] + " §f(§7Copper price §6$pricePerCopper§f)" - } + if (config.visitorCopperPrice) { + val matcher = copperPattern.matcher(line) + if (matcher.matches()) { + val coppers = matcher.group(1).replace(",", "").toInt() + val pricePerCopper = NumberUtil.format((totalPrice / coppers).toInt()) + list[i] = list[i] + " §f(§7Copper price §6$pricePerCopper§f)" } } - - } catch (e: Exception) { - e.printStackTrace() - LorenzUtils.debug("crash!") } } |