diff options
Diffstat (limited to 'src')
4 files changed, 30 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index 75e31ab2a..dd10d8482 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.config import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.features.garden.CropType import com.google.gson.GsonBuilder import io.github.moulberry.moulconfig.observer.PropertyTypeAdapterFactory import io.github.moulberry.moulconfig.processor.BuiltinMoulConfigGuis @@ -36,14 +37,24 @@ class ConfigManager { if (configFile!!.exists()) { try { - BufferedReader(InputStreamReader(FileInputStream(configFile!!), StandardCharsets.UTF_8)).use { reader -> - SkyHanniMod.feature = gson.fromJson( - reader, - Features::class.java - ) + val inputStreamReader = InputStreamReader(FileInputStream(configFile!!), StandardCharsets.UTF_8) + val bufferedReader = BufferedReader(inputStreamReader) + val builder = StringBuilder() + for (line in bufferedReader.lines()) { + val result = fixConfig(line) + builder.append(result) + builder.append("\n") } + + + SkyHanniMod.feature = gson.fromJson( + builder.toString(), + Features::class.java + ) logger.info("Loaded config from file") } catch (e: Exception) { + println("config error") + e.printStackTrace() val backupFile = configFile!!.resolveSibling("config-${System.currentTimeMillis()}-backup.json") logger.error( "Exception while reading $configFile. Will load blank config and save backup to $backupFile", @@ -75,6 +86,18 @@ class ConfigManager { ) } + private fun fixConfig(line: String): String { + var result = line + for (type in CropType.values()) { + val normal = "\"${type.cropName}\"" + val enumName = "\"${type.name}\"" + while (result.contains(normal)) { + result = result.replace(normal, enumName) + } + } + return result + } + fun saveConfig() { try { logger.info("Saving config file") 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 1d71c8553..d81702ffd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt @@ -19,9 +19,6 @@ enum class CropType(val cropName: String, val toolName: String, iconSupplier: () ; val icon by lazy { iconSupplier() } - override fun toString(): String { - return cropName - } companion object { fun getByName(name: String) = values().firstOrNull { it.cropName == name } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt index b1186f533..ca118f665 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt @@ -316,7 +316,7 @@ class GardenCropMilestoneDisplay { lastPlaySoundTime = System.currentTimeMillis() sound.playSound() } - SendTitleHelper.sendTitle("§b$crop $nextTier in $duration", 1_500) + SendTitleHelper.sendTitle("§b${crop.cropName} $nextTier in $duration", 1_500) } } lineMap[3] = Collections.singletonList("§7In §b$duration") diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt index 2a1f8b4dc..a1c632725 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt @@ -104,7 +104,7 @@ class GardenOptimalSpeed { lastWarnTime = System.currentTimeMillis() SendTitleHelper.sendTitle("§cWrong speed!", 3_000) cropInHand?.let { - LorenzUtils.chat("§e[SkyHanni] Wrong speed for $it: §f$currentSpeed §e(§f$optimalSpeed §eis optimal)") + LorenzUtils.chat("§e[SkyHanni] Wrong speed for ${it.cropName}: §f$currentSpeed §e(§f$optimalSpeed §eis optimal)") } } } |