Skip to content

Commit

Permalink
feat: Abstract away onAccessDenied method for ability to override
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeGodSRC committed Nov 9, 2024
1 parent b66ea3c commit 143f1bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ public void onArgumentMissing(CommandContext commandContext, String usage) {
commandContext.sendMessage(MessageType.WARN, "Usage: " + usage);
}

/**
* Method called when the executor does not have permission to execute the
* command.
*
* @param commandContext Context of the command
*/
public void onAccessDenied(CommandContext commandContext) {
commandContext.sendMessage(MessageType.ERROR, "You don't have permission to execute this command!");
}

/**
* In the context in which none of the sub-commands match, this method will be
* called if all arguments match the parameters.
Expand Down Expand Up @@ -181,7 +191,7 @@ public void execute(CommandContext commandContext) {
}

if (!this.canAccess(commandContext)) {
commandContext.sendMessage(MessageType.ERROR, "You don't have permission to execute this command!");
this.onAccessDenied(commandContext);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void execute(CommandContext commandContext) {
}

if (!this.canAccess(commandContext)) {
commandContext.sendMessage(MessageType.ERROR, "You don't have permission to execute this command!");
baseCommand.onAccessDenied(commandContext);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion global.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = 0.7.9b6-SNAPSHOT
version = 0.7.9b7-SNAPSHOT

0 comments on commit 143f1bb

Please sign in to comment.