Skip to content

Commit

Permalink
fixed config load not reporting any errors
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Jan 14, 2024
1 parent acf7060 commit f884503
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 47 deletions.
78 changes: 38 additions & 40 deletions src/main/kotlin/net/ccbluex/liquidbounce/config/ConfigSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ object ConfigSystem {

logger.debug("Reading config ${configurable.loweredName}...")
deserializeConfigurable(configurable, reader())
}.onSuccess {
logger.info("Successfully loaded config '${configurable.loweredName}'.")
}.onFailure {
logger.error("Unable to load config ${configurable.loweredName}", it)
Expand Down Expand Up @@ -197,63 +198,60 @@ object ConfigSystem {
* Deserialize a configurable from a json element
*/
fun deserializeConfigurable(configurable: Configurable, jsonElement: JsonElement) {
runCatching {
val jsonObject = jsonElement.asJsonObject
val jsonObject = jsonElement.asJsonObject

// Handle auto config
AutoConfig.handlePossibleAutoConfig(jsonObject)
// Handle auto config
AutoConfig.handlePossibleAutoConfig(jsonObject)

// Check if the name is the same as the configurable name
if (jsonObject.getAsJsonPrimitive("name").asString != configurable.name) {
throw IllegalStateException()
}
// Check if the name is the same as the configurable name
if (jsonObject.getAsJsonPrimitive("name").asString != configurable.name) {
throw IllegalStateException()
}

val values =
jsonObject.getAsJsonArray("value").map { it.asJsonObject }.associateBy { it["name"].asString!! }
val values =
jsonObject.getAsJsonArray("value").map { it.asJsonObject }.associateBy { it["name"].asString!! }

for (value in configurable.value) {
if (value is Configurable) {
val currentElement = values[value.name] ?: continue
for (value in configurable.value) {
if (value is Configurable) {
val currentElement = values[value.name] ?: continue

runCatching {
if (value is ChoiceConfigurable) {
runCatching {
val newActive = currentElement["active"].asString
runCatching {
if (value is ChoiceConfigurable) {
runCatching {
val newActive = currentElement["active"].asString

value.setFromValueName(newActive)
}.onFailure { it.printStackTrace() }
value.setFromValueName(newActive)
}.onFailure { it.printStackTrace() }

val choices = currentElement["choices"].asJsonObject
val choices = currentElement["choices"].asJsonObject

for (choice in value.choices) {
runCatching {
val choiceElement = choices[choice.name]
?: error("Choice ${choice.name} not found")
for (choice in value.choices) {
runCatching {
val choiceElement = choices[choice.name]
?: error("Choice ${choice.name} not found")

deserializeConfigurable(choice, choiceElement)
}.onFailure {
logger.error("Unable to deserialize choice ${choice.name}", it)
}
deserializeConfigurable(choice, choiceElement)
}.onFailure {
logger.error("Unable to deserialize choice ${choice.name}", it)
}
}
}.onFailure {
logger.error("Unable to deserialize configurable ${value.name}", it)
}

// Deserialize the rest of the configurable
deserializeConfigurable(value, currentElement)
} else {
val currentElement = values[value.name] ?: continue

runCatching {
value.deserializeFrom(clientGson, currentElement["value"])
}.onFailure {
logger.error("Unable to deserialize value ${value.name}", it)
}
}.onFailure {
logger.error("Unable to deserialize configurable ${value.name}", it)
}
} else {
val currentElement = values[value.name] ?: continue

runCatching {
value.deserializeFrom(clientGson, currentElement["value"])
}.onFailure {
logger.error("Unable to deserialize value ${value.name}", it)
}
}
}.onFailure {
logger.error("Unable to deserialize configurable ${configurable.name}", it)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ import net.ccbluex.liquidbounce.features.command.builder.CommandBuilder
import net.ccbluex.liquidbounce.features.command.builder.ParameterBuilder
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.ModuleManager
import net.ccbluex.liquidbounce.utils.client.chat
import net.ccbluex.liquidbounce.utils.client.logger
import net.ccbluex.liquidbounce.utils.client.regular
import net.ccbluex.liquidbounce.utils.client.variable
import net.ccbluex.liquidbounce.utils.client.*
import net.ccbluex.liquidbounce.utils.io.HttpClient.get
import net.minecraft.text.Text

Expand Down Expand Up @@ -70,7 +67,7 @@ object CommandConfig {
ConfigSystem.deserializeConfigurable(ModuleManager.modulesConfigurable, reader(),
ConfigSystem.autoConfigGson)
}.onFailure {
chat(regular(command.result("failedToLoad", variable(name))))
chat(red(command.result("failedToLoad", variable(name))))
}.onSuccess {
chat(regular(command.result("loaded", variable(name))))
}
Expand All @@ -82,7 +79,7 @@ object CommandConfig {
ConfigSystem.deserializeConfigurable(ModuleManager.modulesConfigurable, reader(),
ConfigSystem.autoConfigGson)
}.onFailure {
chat(regular(command.result("failedToLoad", variable(name))))
chat(red(command.result("failedToLoad", variable(name))))
}.onSuccess {
chat(regular(command.result("loaded", variable(name))))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import net.ccbluex.liquidbounce.features.command.builder.ParameterBuilder
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.ModuleManager
import net.ccbluex.liquidbounce.utils.client.chat
import net.ccbluex.liquidbounce.utils.client.red
import net.ccbluex.liquidbounce.utils.client.regular
import net.ccbluex.liquidbounce.utils.client.variable
import net.minecraft.util.Util
Expand Down Expand Up @@ -64,7 +65,7 @@ object CommandLocalConfig {
ConfigSystem.deserializeConfigurable(ModuleManager.modulesConfigurable, reader(),
ConfigSystem.autoConfigGson)
}.onFailure {
chat(regular(command.result("failedToLoad", variable(name))))
chat(red(command.result("failedToLoad", variable(name))))
}.onSuccess {
chat(regular(command.result("loaded", variable(name))))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ fun variable(text: MutableText) = text.styled { it.withColor(Formatting.GOLD) }

fun variable(text: String) = text.asText().styled { it.withColor(Formatting.GOLD) }

fun warning(text: MutableText) = text.styled { it.withColor(Formatting.YELLOW) }

fun red(text: MutableText) = text.styled { it.withColor(Formatting.RED) }

fun chat(vararg texts: Text, prefix: Boolean = true) {
val literalText = if (prefix) clientPrefix.copy() else Text.literal("")
texts.forEach { literalText.append(it) }
Expand Down

0 comments on commit f884503

Please sign in to comment.