Skip to content

Commit

Permalink
fix: set RootCommand permission by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Oct 13, 2024
1 parent 8605bd0 commit f1f37ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ open class IdoCommand(
requires { init(it) }
}

fun requiresPermission(permission: String) = requires {
sender.hasPermission("$permission.*") || sender.hasPermission(permission)
/** The permission to use for this command. If null, use default of plugin.commandname. If it is blank, require no permission */
var permission: String? = null
fun requiresPermission(permission: String) {
this.permission = permission
}

/** Specifies an end node for the command that runs something, only one executes block can run per command execution. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class RootIdoCommands(
internal fun buildEach() {
rootCommands.forEach { command ->
commands.register(
command.build(),
command.apply {
val permission = permission ?: "${plugin.name}.$name"
if (permission.isNotEmpty()) requires { sender.hasPermission("$permission.*") || sender.hasPermission(permission) }
}.build(),
command.description,
command.aliases
)
Expand Down

0 comments on commit f1f37ac

Please sign in to comment.