From 1e52428d3939d0b579cbc156b4e30fb4e8cdc342 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 19 Apr 2023 23:47:02 +0200 Subject: Code cleanup --- src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt | 2 +- src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt | 2 +- src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt | 7 +++---- .../hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt | 2 +- .../hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt | 2 +- .../skyhanni/features/garden/farming/DicerRngDropCounter.kt | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt index 251ec3ac2..f4c2802f2 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt @@ -44,7 +44,7 @@ class GardenCropMilestones { var matcher = cropPattern.matcher(line) if (matcher.matches()) { val name = matcher.group(1) - crop = CropType.getByName(name) ?: continue + crop = CropType.getByNameOrNull(name) ?: continue } matcher = totalPattern.matcher(line) if (matcher.matches()) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt index 21c35837c..07b796b33 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt @@ -29,7 +29,7 @@ class GardenCropUpgrades { if (event.inventoryName != "Crop Upgrades") return event.inventoryItems.forEach { (_, item) -> val crop = item.name?.removeColor()?.let { - CropType.getByName(it) + CropType.getByNameOrNull(it) } ?: return@forEach val level = item.getLore().firstNotNullOfOrNull { tierPattern.matchEntire(it)?.groups?.get(1)?.value?.toIntOrNull() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt index c8888b688..df86b08d1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt @@ -33,17 +33,16 @@ enum class CropType( val multiplier by lazy { if (this == SUGAR_CANE || this == CACTUS) 2 else 1 } companion object { - fun getByName(cropName: String) = values().firstOrNull { it.cropName == cropName } + fun getByNameOrNull(cropName: String) = values().firstOrNull { it.cropName == cropName } - // TODO find better name for this method - fun getByNameNoNull(name: String) = getByName(name) ?: throw RuntimeException("No valid crop type '$name'") + fun getByName(name: String) = getByNameOrNull(name) ?: throw RuntimeException("No valid crop type '$name'") fun getByItemName(itemName: String): CropType? { if (itemName == "Red Mushroom" || itemName == "Brown Mushroom") return MUSHROOM if (itemName == "Seeds") return WHEAT - return getByName(itemName) + return getByNameOrNull(itemName) } fun IBlockState.getCropType(): CropType? { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt index 33a605379..c42ab8d6f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt @@ -35,7 +35,7 @@ class GardenCropMilestoneFix { val progress = progressCrops * (percentage / 100) val smallestPercentage = progressCrops * 0.0005 - val crop = CropType.getByName(cropName) + val crop = CropType.getByNameOrNull(cropName) if (crop == null) { LorenzUtils.debug("GardenCropMilestoneFix: crop is null: '$cropName'") return 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 c5c5d6978..1037d0bb3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -118,7 +118,7 @@ class GardenNextJacobContest { for (line in lore) { val matcherCrop = patternCrop.matcher(line) if (!matcherCrop.matches()) continue - crops.add(CropType.getByNameNoNull(matcherCrop.group(1))) + crops.add(CropType.getByName(matcherCrop.group(1))) } val contest = FarmingContest(startTime + contestDuration, crops) contests[startTime] = contest diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt index c190217bb..ca15c038a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt @@ -118,7 +118,7 @@ class DicerRngDropCounter { fun onConfigLoad(event: ConfigLoadEvent) { for ((internalName, amount) in SkyHanniMod.feature.hidden.gardenDicerRngDrops) { val split = internalName.split(".") - val crop = CropType.getByNameNoNull(split[0]) + val crop = CropType.getByName(split[0]) val rarityName = split[1] val rarity = DropRarity.valueOf(rarityName) drops[crop]!![rarity] = amount -- cgit