From 966eaa282e604939b7e295279a5f0b22ba1c6e0f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 2 Sep 2023 12:13:17 +0200 Subject: code cleanup, better error handling --- src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt | 2 +- .../skyhanni/features/garden/farming/FarmingWeightDisplay.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') 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 084c8d9e9..3bb3534e3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt @@ -39,7 +39,7 @@ enum class CropType( return entries.firstOrNull { it.cropName == itemName } } - fun getByName(name: String) = getByNameOrNull(name) ?: throw RuntimeException("No valid crop type '$name'") + fun getByName(name: String) = getByNameOrNull(name) ?: error("No valid crop type '$name'") fun IBlockState.getCropType(): CropType? { return when (block) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt index 30473f39f..7a993f0de 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt @@ -409,13 +409,13 @@ class FarmingWeightDisplay { private fun CropType.getLocalCounter() = localCounter[this] ?: 0L private fun CropType.getFactor(): Double { - return factorPerCrop[this] ?: backupFactors[this]!! + return factorPerCrop[this] ?: backupFactors[this] ?: error("Crop $this not in backupFactors!") } fun lookUpCommand(it: Array) { val name = if (it.size == 1) it[0] else LorenzUtils.getPlayerName() OSUtils.openBrowser("https://elitebot.dev/@$name/") - LorenzUtils.chat("§e[SkyHanni] Opening Farming Profile from §b$name") + LorenzUtils.chat("§e[SkyHanni] Opening Farming Profile of player §b$name") } private val factorPerCrop = mutableMapOf() @@ -430,7 +430,7 @@ class FarmingWeightDisplay { val result = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) }.asJsonObject for (crop in result.entrySet()) { - val cropType = CropType.entries.firstOrNull { it.cropName == crop.key } ?: continue + val cropType = CropType.getByName(crop.key) factorPerCrop[cropType] = crop.value.asDouble } } -- cgit