40 lines
1.4 KiB
Kotlin
40 lines
1.4 KiB
Kotlin
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
|
|
import java.util.*
|
|
|
|
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) {
|
|
val simplifiedValueName = value.name.lowercase(Locale.getDefault()).replace(" ", "")
|
|
|
|
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'")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|