hibiscus/src/main/kotlin/codes/som/hibiscus/api/feature/FeatureCommand.kt

40 lines
1.4 KiB
Kotlin
Raw Normal View History

2022-02-03 21:43:06 +00:00
package codes.som.hibiscus.api.feature
import codes.som.hibiscus.HibiscusLog
import codes.som.hibiscus.HibiscusMod
import codes.som.hibiscus.api.command.Command
import codes.som.hibiscus.api.command.CommandContext
2022-02-04 18:17:49 +00:00
import java.util.*
2022-02-03 21:43:06 +00:00
class FeatureCommand(feature: Feature) : Command(feature.name.replace(" ", "").lowercase()) {
init {
branch {
feature.enabled = !feature.enabled
if (HibiscusMod.commands.context == CommandContext.MANUAL) {
val state = if (feature.enabled) "enabled" else "disabled"
HibiscusLog.info("${feature.name} is now $state.")
}
}
if (feature.values.exist()) {
for (value in feature.values) {
2022-02-04 18:17:49 +00:00
val simplifiedValueName = value.name.lowercase(Locale.getDefault()).replace(" ", "")
2022-02-03 21:43:06 +00:00
branch(simplifiedValueName) {
HibiscusLog.info("Value of '${value.name}': " + value.getValueAsString())
}
branch(simplifiedValueName) { newValue: String ->
try {
value.setValueFromString(newValue)
HibiscusLog.info("Value of '${value.name}': " + value.getValueAsString())
} catch (e: Exception) {
HibiscusLog.info("Could not set the value of '${value.name}' to '$newValue'")
}
}
}
}
}
}