diff options
Diffstat (limited to 'src')
4 files changed, 47 insertions, 53 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt index 0e2ed1fef..5294d79a1 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt @@ -6,15 +6,12 @@ import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded -import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern class GardenCropMilestones { - private val overflowPattern = Pattern.compile("(?:.*) §e(.*)§6\\/(?:.*)") - private val nextTierPattern = Pattern.compile("§7Progress to Tier (.*): §e(?:.*)") + private val cropPattern = Pattern.compile("§7Harvest §f(.*) §7on .*") + private val totalPattern = Pattern.compile("§7Total: §a(.*)") // Add when api support is there // @SubscribeEvent @@ -43,31 +40,17 @@ class GardenCropMilestones { if (event.inventoryName != "Crop Milestones") return for ((_, stack) in event.inventoryItems) { - val cropName = stack.name?.removeColor() ?: continue - val crop = CropType.getByName(cropName) ?: continue - - val lore = stack.getLore() - var cropForTier = 0L - var next = false - for (line in lore) { - if (line.contains("Progress to Tier")) { - val matcher = nextTierPattern.matcher(line) - if (matcher.matches()) { - val nextTier = matcher.group(1).romanToDecimalIfNeeded() - val currentTier = nextTier - 1 - cropForTier = getCropsForTier(currentTier) - } - next = true - continue + var crop: CropType? = null + for (line in stack.getLore()) { + var matcher = cropPattern.matcher(line) + if (matcher.matches()) { + val name = matcher.group(1) + crop = CropType.getByName(name) ?: continue } - if (next) { - val matcher = overflowPattern.matcher(line) - if (matcher.matches()) { - val rawNumber = matcher.group(1) - val overflow = rawNumber.formatNumber() - crop.setCounter(cropForTier + overflow) - } - next = false + matcher = totalPattern.matcher(line) + if (matcher.matches()) { + val amount = matcher.group(1).replace(",", "").toLong() + crop?.setCounter(amount) } } } @@ -80,7 +63,9 @@ class GardenCropMilestones { fun CropType.getCounter() = cropCounter[this]!! - fun CropType.setCounter(counter: Long) { cropCounter[this] = counter } + fun CropType.setCounter(counter: Long) { + cropCounter[this] = counter + } fun getTierForCrops(crops: Long): Int { var tier = 0 diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt index b5927d31f..15eff6a85 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.chat.playerchat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.features.dungeon.DungeonMilestonesDisplay import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import net.minecraft.util.ChatComponentText import net.minecraft.util.IChatComponent @@ -13,8 +14,8 @@ class PlayerChatModifier { init { patterns.add("§(?:a|b|6)\\[(?:VIP|MVP)(?:(?:§.|\\+)*)](?: {1,2})(?:§[7ab6])?(\\w{2,16})".toRegex()) // ranked player everywhere - patterns.add("§(?:7|a|b|6)((?:\\w+){2,16})§r(?!§7x)".toRegex()) // nons in notification message - patterns.add("(?:§7 )?§7((?:\\w+){2,16})§7§r".toRegex()) // nons user chat + patterns.add("§(?:7|a|b|6)((?:\\w){2,16})§r(?!§7x)".toRegex()) // nons in notification message + patterns.add("(?:§7 )?§7((?:\\w){2,16})§7§r".toRegex()) // nons user chat } @SubscribeEvent @@ -68,19 +69,19 @@ class PlayerChatModifier { } } -// if (SkyHanniMod.feature.chat.playerRankHider) { -// for (pattern in patterns) { -// string = string.replace(pattern, "§b$1") -// } -// string = string.replace("§(?:7|a|b|6)((?:\\w+){2,16})'s", "§b$1's") -// string = string.replace("§(?:7|a|b|6)((?:\\w+){2,16}) (§.)", "§b$1 $2") -// -// // TODO remove workaround -// if (!DungeonMilestonesDisplay.isMilestoneMessage(input)) { -// //all players same color in chat -// string = string.replace("§r§7: ", "§r§f: ") -// } -// } + if (SkyHanniMod.feature.chat.playerRankHider) { + for (pattern in patterns) { + string = string.replace(pattern, "§b$1") + } + string = string.replace("§(?:7|a|b|6)((?:\\w+){2,16})'s", "§b$1's") + string = string.replace("§(?:7|a|b|6)((?:\\w+){2,16}) (§.)", "§b$1 $2") + + // TODO remove workaround + if (!DungeonMilestonesDisplay.isMilestoneMessage(input)) { + //all players same color in chat + string = string.replace("§r§7: ", "§r§f: ") + } + } if (SkyHanniMod.feature.markedPlayers.highlightInChat) { for (markedPlayer in MarkedPlayerManager.playerNamesToMark) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt index 790a7020f..4de998443 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt @@ -53,7 +53,9 @@ class SkyMartBestProfit { name = "§9Sunder I" } - iconMap[name] = NEUItems.getItemStack(internalName) + NEUItems.getItemStackOrNull(internalName)?.let { + iconMap[name] = it + } val advancedStats = if (config.skyMartCopperPriceAdvancedStats) { " §7(§6$priceFormat §7/ §c$amountFormat Copper§7)" @@ -80,12 +82,13 @@ class SkyMartBestProfit { val longest = keys.map { it.first }.maxOfOrNull { renderer.getStringWidth(it.removeColor()) } ?: 0 for ((name, second) in keys) { - val itemStack = iconMap[name]!! var displayName = "$name§f:" while (renderer.getStringWidth(displayName.removeColor()) < longest) { displayName += " " } - newList.add(listOf(itemStack, "$displayName $second")) + iconMap[name]?.let { + newList.add(listOf(it, "$displayName $second")) + } } return newList } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 568ccbb87..8633dcadd 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -55,21 +55,26 @@ object NEUItems { return result } - fun getItemStack(internalName: String): ItemStack { + fun getItemStackOrNull(internalName: String): ItemStack? { if (itemCache.contains(internalName)) { return itemCache[internalName]!!.copy() } val itemStack = ItemResolutionQuery(manager) .withKnownInternalName(internalName) - .resolveToItemStack() - if (itemStack == null) { + .resolveToItemStack() ?: return null + itemCache[internalName] = itemStack + return itemStack.copy() + } + + fun getItemStack(internalName: String): ItemStack { + val stack = getItemStackOrNull(internalName) + if (stack == null) { val error = "ItemResolutionQuery returns null for internalName $internalName" LorenzUtils.error(error) throw RuntimeException(error) } - itemCache[internalName] = itemStack - return itemStack.copy() + return stack } fun isVanillaItem(item: ItemStack) = manager.auctionManager.isVanillaItem(item.getInternalName()) |