File tree Expand file tree Collapse file tree 4 files changed +12
-5
lines changed
API/src/main/java/xyz/bitsquidd/bits/lib/command Expand file tree Collapse file tree 4 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ private void processCommandMethod(
140140 if (!paramBranch .isEmpty ()) workingBranch = paramBranch .getLast ();
141141
142142 // Add method requirements
143- workingBranch .requires (ctx -> methodInfo .getRequirements ().stream ()
143+ workingBranch .requires (ctx -> methodInfo .getRequirements (commandBuilder . getPermissionString () ).stream ()
144144 .allMatch (requirement -> requirement .test (bitsCommandManager .createSourceContext (ctx )))
145145 );
146146 workingBranch .executes (createCommandExecution (commandBuilder , methodInfo ));
Original file line number Diff line number Diff line change 99
1010/**
1111 * Specifies an extra string permission to be required to execute the command.
12+ * <p>
13+ * Note: this is appended onto the end of the base permission string i.e. "bits.command.command_name.permission"
14+ * as there are few situations where you should need to share permissions between commands.
1215 */
1316@ Target ({ElementType .TYPE , ElementType .METHOD })
1417@ Retention (RetentionPolicy .RUNTIME )
Original file line number Diff line number Diff line change 2121import java .util .stream .Stream ;
2222
2323@ NullMarked
24- public class BitsCommandBuilder {
24+ public final class BitsCommandBuilder {
2525 private @ Nullable BitsCommand commandInstance ;
2626 private final Class <? extends BitsCommand > commandClass ;
2727
@@ -107,7 +107,7 @@ public Set<BitsCommandRequirement> getRequirements() {
107107 Permission permissionAnnotation = commandClass .getAnnotation (Permission .class );
108108 if (permissionAnnotation != null ) {
109109 requirements .addAll (Arrays .stream (permissionAnnotation .value ())
110- .map (PermissionRequirement :: of )
110+ .map (appended -> PermissionRequirement . of ( permissionString + "." + appended ) )
111111 .toList ());
112112 }
113113
@@ -123,4 +123,8 @@ public Set<BitsCommandRequirement> getRequirements() {
123123 return requirements ;
124124 }
125125
126+ public String getPermissionString () {
127+ return permissionString ;
128+ }
129+
126130}
Original file line number Diff line number Diff line change @@ -78,14 +78,14 @@ public String literalName() {
7878 }
7979
8080 //TODO merge with BitsCommandBuilder permission gathering?
81- public List <BitsCommandRequirement > getRequirements () {
81+ public List <BitsCommandRequirement > getRequirements (String permissionString ) {
8282 List <BitsCommandRequirement > requirements = new ArrayList <>();
8383
8484 // Gather permission strings and convert them to requirements.
8585 Permission permissionAnnotation = method .getAnnotation (Permission .class );
8686 if (permissionAnnotation != null ) {
8787 requirements .addAll (Arrays .stream (permissionAnnotation .value ())
88- .map (PermissionRequirement :: of )
88+ .map (appended -> PermissionRequirement . of ( permissionString + "." + appended ) )
8989 .toList ());
9090 }
9191
You can’t perform that action at this time.
0 commit comments