Skip to content

Commit

Permalink
Fix command permissions for default actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal committed Feb 16, 2022
1 parent 9e43dab commit 02f8d73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private class CategoryPermission implements CommandPermission {
for (CommandCategory category : categories.values())
if (category.getPermission().canExecute(actor))
return true;
return false;
return defaultAction != null && defaultAction.hasPermission(actor);
}
}

Expand Down
25 changes: 15 additions & 10 deletions common/src/main/java/revxrsal/commands/core/BaseCommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,26 @@ public BaseCommandHandler() {
for (BaseCommandCategory category : categories.values()) {
CommandPath categoryPath = category.getPath().getCategoryPath();
category.parent(categoryPath == null ? null : categories.get(categoryPath));
findPermission(category.defaultAction);
}
command_loop:
for (CommandExecutable executable : executables.values()) {
if (!executable.permissionSet) {
for (PermissionReader reader : permissionReaders) {
CommandPermission p = reader.getPermission(executable);
if (p != null) {
executable.permissionSet = true;
executable.setPermission(p);
continue command_loop;
}
findPermission(executable);
}
return this;
}

private void findPermission(@Nullable CommandExecutable executable) {
if (executable == null) return;
if (!executable.permissionSet) {
for (PermissionReader reader : permissionReaders) {
CommandPermission p = reader.getPermission(executable);
if (p != null) {
executable.permissionSet = true;
executable.setPermission(p);
return;
}
}
}
return this;
}

public Set<PermissionReader> getPermissionReaders() {
Expand Down

0 comments on commit 02f8d73

Please sign in to comment.