diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-19 23:47:02 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-19 23:47:02 +0200 |
commit | 1e52428d3939d0b579cbc156b4e30fb4e8cdc342 (patch) | |
tree | 0a2aa3b81a5034654a7a135975d830606eb79641 /src/main/java/at | |
parent | 50dfb62bad66e9bdb04cca17a2dd32a69b108265 (diff) | |
download | skyhanni-1e52428d3939d0b579cbc156b4e30fb4e8cdc342.tar.gz skyhanni-1e52428d3939d0b579cbc156b4e30fb4e8cdc342.tar.bz2 skyhanni-1e52428d3939d0b579cbc156b4e30fb4e8cdc342.zip |
Code cleanup
Diffstat (limited to 'src/main/java/at')
6 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 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 |