Skip to content

Commit

Permalink
feat(bukkit): add /sayanvanish feature <feature> <enable/disable> c…
Browse files Browse the repository at this point in the history
…ommand
  • Loading branch information
Syrent committed Jun 2, 2024
1 parent ba914d5 commit cbba680
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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<SenderExtension, String>("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<String>("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<String>("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?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -24,6 +25,15 @@ data class LanguageConfig(
val playerNotFound: String = "<red>Player not found",
)

@ConfigSerializable
data class Feature(
val featureNotFound: String = "<red>Feature not found",
val featureEnabled: String = "<gray><gold><feature></gold> has been enabled.",
val featureDisabled: String = "<gray><gold><feature></gold> has been disabled.",
val alreadyDisabled: String = "<gray><gold><feature></gold> is already disabled.",
val alreadyEnabled: String = "<gray><gold><feature></gold> is already enabled.",
)

@ConfigSerializable
data class Vanish(
val vanishStateUpdate: String = "<gray>Your vanish state has been updated to <state>.",
Expand Down

0 comments on commit cbba680

Please sign in to comment.