diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt index f4c2802f2..d07172609 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt @@ -5,12 +5,13 @@ import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class GardenCropMilestones { - private val cropPattern = "§7Harvest §f(.*) §7on .*".toPattern() - private val totalPattern = "§7Total: §a(.*)".toPattern() + private val cropPattern = "§7Harvest §f(?<name>.*) §7on .*".toPattern() + private val totalPattern = "§7Total: §a(?<name>.*)".toPattern() // Add when api support is there // @SubscribeEvent @@ -41,14 +42,12 @@ class GardenCropMilestones { for ((_, stack) in event.inventoryItems) { var crop: CropType? = null for (line in stack.getLore()) { - var matcher = cropPattern.matcher(line) - if (matcher.matches()) { - val name = matcher.group(1) - crop = CropType.getByNameOrNull(name) ?: continue + cropPattern.matchMatcher(line) { + val name = group("name") + crop = CropType.getByNameOrNull(name) } - matcher = totalPattern.matcher(line) - if (matcher.matches()) { - val amount = matcher.group(1).replace(",", "").toLong() + totalPattern.matchMatcher(line) { + val amount = group("name").replace(",", "").toLong() crop?.setCounter(amount) } } |