diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-06-09 22:57:48 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-06-09 22:57:48 +0200 |
commit | c6dbecb3e1bd1edd795fd18ee9e6628f7c702e47 (patch) | |
tree | 5c16fefd5f80abc404bd94f6838fbab0f463b781 /src/main | |
parent | 4ac597cab7c261b169c7a7abf005db00fc6c4fb4 (diff) | |
download | skyhanni-c6dbecb3e1bd1edd795fd18ee9e6628f7c702e47.tar.gz skyhanni-c6dbecb3e1bd1edd795fd18ee9e6628f7c702e47.tar.bz2 skyhanni-c6dbecb3e1bd1edd795fd18ee9e6628f7c702e47.zip |
moved tooltip logic into a separate method
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt | 121 |
1 files changed, 62 insertions, 59 deletions
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 60e2c83b9..9127d7af6 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 @@ -329,66 +329,11 @@ class GardenVisitorFeatures { if (event.itemStack.name != "§aAccept Offer") return if (offerCache.isEmpty()) { - var totalPrice = 0.0 - var timeRequired = -1L - val iterator = event.toolTip.listIterator() - for (line in iterator) { - val formattedLine = line.substring(4) - val (itemName, amount) = ItemUtils.readItemAmount(formattedLine) - if (itemName != null) { - val internalName = NEUItems.getInternalNameOrNull(itemName) - if (internalName != null) { - price = NEUItems.getPrice(internalName) * amount - - if (config.visitorShowPrice) { - val format = NumberUtil.format(price) - iterator.set("$formattedLine §7(§6$format§7)") - } - if (totalPrice == 0.0) { - totalPrice = price - val multiplier = NEUItems.getMultiplier(internalName) - val rawName = NEUItems.getItemStack(multiplier.first).name?.removeColor() ?: continue - getByNameOrNull(rawName)?.let { - val cropAmount = multiplier.second.toLong() * amount - val formattedAmount = LorenzUtils.formatInteger(cropAmount) - val formattedName = "§e$formattedAmount§7x ${it.cropName} " - val formattedSpeed = it.getSpeed()?.let { speed -> - timeRequired = cropAmount / speed - val duration = TimeUtils.formatDuration(timeRequired * 1000) - "in §b$duration" - } ?: "§cno speed data!" - if (config.visitorExactAmountAndTime) { - iterator.add("§7- $formattedName($formattedSpeed§7)") - } - } - } - } - } - - if (config.visitorExperiencePrice) { - gardenExperiencePattern.matchMatcher(formattedLine) { - val gardenExp = group("amount").replace(",", "").toInt() - val pricePerCopper = NumberUtil.format((totalPrice / gardenExp).toInt()) - iterator.set("$formattedLine §7(§6$pricePerCopper §7per)") - } - } - - copperPattern.matchMatcher(formattedLine) { - val copper = group("amount").replace(",", "").toInt() - val pricePerCopper = NumberUtil.format((totalPrice / copper).toInt()) - val timePerCopper = TimeUtils.formatDuration((timeRequired / copper) * 1000) - var copperLine = formattedLine - if (config.visitorCopperPrice) copperLine += " §7(§6$pricePerCopper §7per)" - if (config.visitorCopperTime) { - copperLine += if (timeRequired != -1L) " §7(§b$timePerCopper §7per)" else " §7(§cno speed data!§7)" - } - iterator.set(copperLine) - } - } + drawToolTip(event.toolTip.listIterator()) val temp = event.toolTip.listIterator() - for (line in temp) { - offerCache.add(line) - } + for (line in temp) { + offerCache.add(line) + } } else { val iterator = event.toolTip.listIterator() for (i in iterator) { @@ -401,6 +346,64 @@ class GardenVisitorFeatures { } + private fun drawToolTip(iterator: MutableListIterator<String>) { + var totalPrice = 0.0 + var timeRequired = -1L + for (line in iterator) { + val formattedLine = line.substring(4) + val (itemName, amount) = ItemUtils.readItemAmount(formattedLine) + if (itemName != null) { + val internalName = NEUItems.getInternalNameOrNull(itemName) + if (internalName != null) { + price = NEUItems.getPrice(internalName) * amount + + if (config.visitorShowPrice) { + val format = NumberUtil.format(price) + iterator.set("$formattedLine §7(§6$format§7)") + } + if (totalPrice == 0.0) { + totalPrice = price + val multiplier = NEUItems.getMultiplier(internalName) + val rawName = NEUItems.getItemStack(multiplier.first).name?.removeColor() ?: continue + getByNameOrNull(rawName)?.let { + val cropAmount = multiplier.second.toLong() * amount + val formattedAmount = LorenzUtils.formatInteger(cropAmount) + val formattedName = "§e$formattedAmount§7x ${it.cropName} " + val formattedSpeed = it.getSpeed()?.let { speed -> + timeRequired = cropAmount / speed + val duration = TimeUtils.formatDuration(timeRequired * 1000) + "in §b$duration" + } ?: "§cno speed data!" + if (config.visitorExactAmountAndTime) { + iterator.add("§7- $formattedName($formattedSpeed§7)") + } + } + } + } + } + + if (config.visitorExperiencePrice) { + gardenExperiencePattern.matchMatcher(formattedLine) { + val gardenExp = group("amount").replace(",", "").toInt() + val pricePerCopper = NumberUtil.format((totalPrice / gardenExp).toInt()) + iterator.set("$formattedLine §7(§6$pricePerCopper §7per)") + } + } + + copperPattern.matchMatcher(formattedLine) { + val copper = group("amount").replace(",", "").toInt() + val pricePerCopper = NumberUtil.format((totalPrice / copper).toInt()) + val timePerCopper = TimeUtils.formatDuration((timeRequired / copper) * 1000) + var copperLine = formattedLine + if (config.visitorCopperPrice) copperLine += " §7(§6$pricePerCopper §7per)" + if (config.visitorCopperTime) { + copperLine += if (timeRequired != -1L) " §7(§b$timePerCopper §7per)" else " §7(§cno speed data!§7)" + } + iterator.set(copperLine) + } + } + } + @SubscribeEvent fun onTick(event: TickEvent.ClientTickEvent) { if (!GardenAPI.inGarden()) return |