Skip to content

Commit

Permalink
fix: Apply permission requirement right before executes block instead…
Browse files Browse the repository at this point in the history
… of at initial command, otherwise parent commands override permissions for children
  • Loading branch information
0ffz committed Feb 2, 2025
1 parent 14be99c commit c187bab
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ open class IdoCommand(

/** Specifies an end node for the command that runs something, only one executes block can run per command execution. */
inline fun executes(crossinline run: IdoCommandContext.() -> Unit) = edit {
// Apply command permission
permission
?.takeIf { it.isNotEmpty() }
?.let { perm -> requires { it.sender.hasPermissionRecursive(perm) } }

executes { context ->
try {
run(IdoCommandContext(context))
Expand Down Expand Up @@ -171,10 +176,6 @@ open class IdoCommand(
}

internal fun build(): LiteralCommandNode<CommandSourceStack> {
// Apply default command permission
permission?.takeIf { it.isNotEmpty() }
?.let { perm -> initial.requires { it.sender.hasPermissionRecursive(perm) } }

// Apply render steps to command sequentially
render().fold(initial as IdoArgBuilder) { acc, curr ->
curr.foldLeft(acc)
Expand Down

0 comments on commit c187bab

Please sign in to comment.