diff --git a/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/command/SayanVanishCommand.kt b/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/command/SayanVanishCommand.kt index b931fa69..2ca4a4a5 100644 --- a/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/command/SayanVanishCommand.kt +++ b/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/command/SayanVanishCommand.kt @@ -143,15 +143,7 @@ class SayanVanishCommand : StickyCommand("sayanvanish", "vanish", "v") { } Features.features.clear() RegisteredFeatureHandler.process() - /*settings.vanish.features.forEach { feature -> - feature.enabled = false - feature.disable() - } - settings.vanish.features.clear()*/ settings = SettingsConfig.fromConfig() ?: SettingsConfig.defaultConfig() - /*settings.vanish.features.forEach { - if (it.enabled) it.enable() - }*/ databaseConfig = DatabaseConfig.fromConfig() ?: DatabaseConfig.defaultConfig() sender.sendMessage(language.general.reloaded.component()) } @@ -201,6 +193,59 @@ class SayanVanishCommand : StickyCommand("sayanvanish", "vanish", "v") { sender.sendMessage(language.vanish.levelGet.component(Placeholder.unparsed("player", target.name ?: "N/A"), Placeholder.unparsed("level", (user?.vanishLevel ?: 0).toString()))) } .build()) + + val featureLiteral = builder + .literal("feature") + .permission(constructBasePermission("feature")) + .required( + "feature", + CommandComponent.builder("state", StringParser.stringParser()) + .suggestionProvider { _, _ -> + CompletableFuture.completedFuture(Features.features.map { Suggestion.suggestion(it.id) }) + } + ) + + manager.command(featureLiteral + .literal("disable") + .permission(constructBasePermission("feature.disable")) + .handler { context -> + val sender = context.sender().bukkitSender() + val feature = Features.features.find { it.id == context.get("feature") } ?: let { + sender.sendMessage(language.feature.featureNotFound.component()) + return@handler + } + + if (!feature.enabled) { + sender.sendMessage(language.feature.alreadyDisabled.component(Placeholder.unparsed("feature", feature.id))) + return@handler + } + + feature.disable() + feature.save() + sender.sendMessage(language.feature.featureDisabled.component(Placeholder.unparsed("feature", feature.id))) + } + .build()) + + manager.command(featureLiteral + .literal("enable") + .permission(constructBasePermission("feature.enable")) + .handler { context -> + val sender = context.sender().bukkitSender() + val feature = Features.features.find { it.id == context.get("feature") } ?: let { + sender.sendMessage(language.feature.featureNotFound.component()) + return@handler + } + + if (feature.enabled) { + sender.sendMessage(language.feature.alreadyEnabled.component(Placeholder.unparsed("feature", feature.id))) + return@handler + } + + feature.enable() + feature.save() + sender.sendMessage(language.feature.featureEnabled.component(Placeholder.unparsed("feature", feature.id))) + } + .build()) } private fun sendPasteError(sender: CommandSender, error: Throwable?) { diff --git a/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/config/LanguageConfig.kt b/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/config/LanguageConfig.kt index 6a1c2efe..ed09b4f6 100644 --- a/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/config/LanguageConfig.kt +++ b/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/config/LanguageConfig.kt @@ -10,6 +10,7 @@ public var language: LanguageConfig = LanguageConfig.fromConfig() ?: LanguageCon @ConfigSerializable data class LanguageConfig( val vanish: Vanish = Vanish(), + val feature: Feature = Feature(), val general: General = General(), val paste: Paste = Paste() ) : Config(languageDirectory, "${settings.general.language}.yml") { @@ -24,6 +25,15 @@ data class LanguageConfig( val playerNotFound: String = "Player not found", ) + @ConfigSerializable + data class Feature( + val featureNotFound: String = "Feature not found", + val featureEnabled: String = " has been enabled.", + val featureDisabled: String = " has been disabled.", + val alreadyDisabled: String = " is already disabled.", + val alreadyEnabled: String = " is already enabled.", + ) + @ConfigSerializable data class Vanish( val vanishStateUpdate: String = "Your vanish state has been updated to .",