Skip to content

Commit 5e58320

Browse files
committed
🎨 Permission string ids are now appended onto the end of the base permission.
1 parent dc31ff6 commit 5e58320

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

API/src/main/java/xyz/bitsquidd/bits/lib/command/BrigadierTreeGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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));

API/src/main/java/xyz/bitsquidd/bits/lib/command/annotation/Permission.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
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)

API/src/main/java/xyz/bitsquidd/bits/lib/command/util/BitsCommandBuilder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import 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
}

API/src/main/java/xyz/bitsquidd/bits/lib/command/util/CommandMethodInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)