diff --git a/navauth-common/src/main/kotlin/pl/spcode/navauth/common/command/configurer/CommandConfig.kt b/navauth-common/src/main/kotlin/pl/spcode/navauth/common/command/configurer/CommandConfig.kt new file mode 100644 index 00000000..794fe893 --- /dev/null +++ b/navauth-common/src/main/kotlin/pl/spcode/navauth/common/command/configurer/CommandConfig.kt @@ -0,0 +1,28 @@ +/* + * NavAuth + * Copyright © 2026 Oliwier Fijas (Navio1430) + * + * NavAuth is free software; You can redistribute it and/or modify it under the terms of: + * the GNU Affero General Public License version 3 as published by the Free Software Foundation. + * + * NavAuth is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with NavAuth. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package pl.spcode.navauth.common.command.configurer + +import eu.okaeri.configs.OkaeriConfig +import java.util.Collections.emptyList + +class CommandConfig( + var name: String? = null, // new command name + var enabled: Boolean = true, + var aliases: List = emptyList(), +) : OkaeriConfig() {} diff --git a/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/CommandsConfig.kt b/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/CommandsConfig.kt new file mode 100644 index 00000000..28d06e75 --- /dev/null +++ b/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/CommandsConfig.kt @@ -0,0 +1,41 @@ +/* + * NavAuth + * Copyright © 2026 Oliwier Fijas (Navio1430) + * + * NavAuth is free software; You can redistribute it and/or modify it under the terms of: + * the GNU Affero General Public License version 3 as published by the Free Software Foundation. + * + * NavAuth is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with NavAuth. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package pl.spcode.navauth.common.config + +import eu.okaeri.configs.OkaeriConfig +import eu.okaeri.configs.annotation.Comment +import pl.spcode.navauth.common.command.configurer.CommandConfig + +class CommandsConfig : OkaeriConfig() { + + @Comment( + "This property allows you to configure commands definitions.", + "You can toggle the command and update its name or aliases.", + "", + "You can find command names in docs:", + "https://navio1430.github.io/NavAuth/docs/general/commands.html#available-commands", + "Remember to use command names without the leading slash '/'.", + ) + var commands: MutableMap = + mutableMapOf( + "navauth" to CommandConfig(name = "navauth", aliases = mutableListOf("na"), enabled = true), + "login" to CommandConfig(name = "login", aliases = mutableListOf("l"), enabled = true), + "register" to CommandConfig(name = "register", aliases = mutableListOf("reg"), enabled = true), + ) +} diff --git a/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/GeneralConfig.kt b/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/GeneralConfig.kt index 6336db34..d34abecb 100644 --- a/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/GeneralConfig.kt +++ b/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/GeneralConfig.kt @@ -96,6 +96,8 @@ open class GeneralConfig : OkaeriConfig() { var sessionsConfig = SessionsConfig() + var commandsConfig: CommandsConfig = CommandsConfig() + @Variable("CONFIG_VERSION") @Comment("Config version. DO NOT CHANGE this property!") var configVersion: Int = 0 diff --git a/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/NavAuthVelocity.kt b/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/NavAuthVelocity.kt index a6874917..39eeaf24 100644 --- a/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/NavAuthVelocity.kt +++ b/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/NavAuthVelocity.kt @@ -49,6 +49,7 @@ import pl.spcode.navauth.common.config.MigrationConfig import pl.spcode.navauth.common.infra.database.DatabaseManager import pl.spcode.navauth.common.module.* import pl.spcode.navauth.velocity.command.CommandsRegistry +import pl.spcode.navauth.velocity.command.configurer.CommandConfigurer import pl.spcode.navauth.velocity.infra.command.VelocityInvalidUsageHandler import pl.spcode.navauth.velocity.infra.command.VelocityMissingPermissionExceptionHandler import pl.spcode.navauth.velocity.infra.command.VelocityMissingPermissionHandler @@ -163,6 +164,7 @@ constructor( UserResolveException::class.java, UserResolveExceptionHandler(VelocityAudienceProvider(proxyServer)), ) + .editorGlobal(injector.getInstance(CommandConfigurer::class.java)) .exception( MissingPermissionException::class.java, injector.getInstance(VelocityMissingPermissionExceptionHandler::class.java), diff --git a/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/command/configurer/CommandConfigurer.kt b/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/command/configurer/CommandConfigurer.kt new file mode 100644 index 00000000..5a6ec875 --- /dev/null +++ b/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/command/configurer/CommandConfigurer.kt @@ -0,0 +1,43 @@ +/* + * NavAuth + * Copyright © 2026 Oliwier Fijas (Navio1430) + * + * NavAuth is free software; You can redistribute it and/or modify it under the terms of: + * the GNU Affero General Public License version 3 as published by the Free Software Foundation. + * + * NavAuth is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with NavAuth. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package pl.spcode.navauth.velocity.command.configurer + +import com.google.inject.Inject +import com.velocitypowered.api.command.CommandSource +import dev.rollczi.litecommands.command.builder.CommandBuilder +import dev.rollczi.litecommands.editor.Editor +import pl.spcode.navauth.common.config.CommandsConfig + +class CommandConfigurer @Inject constructor(private val commandConfiguration: CommandsConfig) : + Editor { + + override fun edit(context: CommandBuilder): CommandBuilder { + val command = commandConfiguration.commands[context.name()] ?: return context + + var newContext = context + + if (!command.name.isNullOrEmpty()) { + newContext = context.name(command.name) + } + + val aliasesFiltered = command.aliases.filter { it.isNotEmpty() } + + return newContext.aliases(aliasesFiltered).enabled(command.enabled) + } +}