Merge pull request #99 from lucko/feature/command-permissions
Implement optional permission check method for commands
This commit is contained in:
@@ -26,4 +26,19 @@ public interface Command {
|
||||
default List<String> suggest(@NonNull CommandSource source, @NonNull String[] currentArgs) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to check if the {@code source} has permission to use this command
|
||||
* with the provided {@code args}.
|
||||
*
|
||||
* <p>If this method returns false, the handling will be forwarded onto
|
||||
* the players current server.</p>
|
||||
*
|
||||
* @param source the source of the command
|
||||
* @param args the arguments for this command
|
||||
* @return whether the source has permission
|
||||
*/
|
||||
default boolean hasPermission(@NonNull CommandSource source, @NonNull String[] args) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -29,5 +29,5 @@ public interface PermissionFunction {
|
||||
* @param permission the permission
|
||||
* @return the value the permission is set to
|
||||
*/
|
||||
@NonNull Tristate getPermissionSetting(@NonNull String permission);
|
||||
@NonNull Tristate getPermissionValue(@NonNull String permission);
|
||||
}
|
||||
|
@@ -12,5 +12,15 @@ public interface PermissionSubject {
|
||||
* @param permission the permission to check for
|
||||
* @return whether or not the subject has the permission
|
||||
*/
|
||||
boolean hasPermission(@NonNull String permission);
|
||||
default boolean hasPermission(@NonNull String permission) {
|
||||
return getPermissionValue(permission).asBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the subjects setting for a particular permission.
|
||||
*
|
||||
* @param permission the permission
|
||||
* @return the value the permission is set to
|
||||
*/
|
||||
@NonNull Tristate getPermissionValue(@NonNull String permission);
|
||||
}
|
||||
|
Reference in New Issue
Block a user