mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-14 04:02:00 +01:00
Added PermissionHandler#getPermission
This commit is contained in:
parent
1b7f00f1b9
commit
7700c718aa
@ -12,8 +12,8 @@ import java.util.Objects;
|
|||||||
*/
|
*/
|
||||||
public class Permission {
|
public class Permission {
|
||||||
|
|
||||||
private String permissionName;
|
private final String permissionName;
|
||||||
private NBTCompound data;
|
private final NBTCompound data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new permission object with optional data.
|
* Creates a new permission object with optional data.
|
||||||
|
@ -43,7 +43,7 @@ public interface PermissionHandler {
|
|||||||
* Uses {@link Permission#equals(Object)} internally.
|
* Uses {@link Permission#equals(Object)} internally.
|
||||||
*
|
*
|
||||||
* @param permission the permission to check
|
* @param permission the permission to check
|
||||||
* @return true if the handler has the permission
|
* @return true if the handler has the permission, false otherwise
|
||||||
*/
|
*/
|
||||||
default boolean hasPermission(@NotNull Permission permission) {
|
default boolean hasPermission(@NotNull Permission permission) {
|
||||||
for (Permission permissionLoop : getAllPermissions()) {
|
for (Permission permissionLoop : getAllPermissions()) {
|
||||||
@ -54,21 +54,40 @@ public interface PermissionHandler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link Permission} with the name {@code permissionName}.
|
||||||
|
*
|
||||||
|
* @param permissionName the permission name
|
||||||
|
* @return the permission from its name, null if not found
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
default Permission getPermission(@NotNull String permissionName) {
|
||||||
|
for (Permission permission : getAllPermissions()) {
|
||||||
|
// Verify permission name equality
|
||||||
|
if (permission.getPermissionName().equals(permissionName)) {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets if this handler has the permission with the name {@code permissionName} and which verify the optional
|
* Gets if this handler has the permission with the name {@code permissionName} and which verify the optional
|
||||||
* {@link PermissionVerifier}.
|
* {@link PermissionVerifier}.
|
||||||
*
|
*
|
||||||
* @param permissionName the permission name
|
* @param permissionName the permission name
|
||||||
* @param permissionVerifier the optional verifier
|
* @param permissionVerifier the optional verifier,
|
||||||
* @return true if the handler has the permission
|
* null mean that only the permission name will be used
|
||||||
|
* @return true if the handler has the permission, false otherwise
|
||||||
*/
|
*/
|
||||||
default boolean hasPermission(@NotNull String permissionName, @Nullable PermissionVerifier permissionVerifier) {
|
default boolean hasPermission(@NotNull String permissionName, @Nullable PermissionVerifier permissionVerifier) {
|
||||||
for (Permission permission : getAllPermissions()) {
|
final Permission permission = getPermission(permissionName);
|
||||||
if (permission.getPermissionName().equals(permissionName)) {
|
|
||||||
return permissionVerifier != null ?
|
if (permission != null) {
|
||||||
permissionVerifier.isValid(permission.getNBTData()) :
|
// Verify using the permission verifier
|
||||||
true;
|
return permissionVerifier != null ?
|
||||||
}
|
permissionVerifier.isValid(permission.getNBTData()) :
|
||||||
|
true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -77,7 +96,7 @@ public interface PermissionHandler {
|
|||||||
* Gets if this handler has the permission with the name {@code permissionName}.
|
* Gets if this handler has the permission with the name {@code permissionName}.
|
||||||
*
|
*
|
||||||
* @param permissionName the permission name
|
* @param permissionName the permission name
|
||||||
* @return true if the handler has the permission
|
* @return true if the handler has the permission, false otherwise
|
||||||
*/
|
*/
|
||||||
default boolean hasPermission(@NotNull String permissionName) {
|
default boolean hasPermission(@NotNull String permissionName) {
|
||||||
return hasPermission(permissionName, null);
|
return hasPermission(permissionName, null);
|
||||||
|
Loading…
Reference in New Issue
Block a user