mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 19:18:12 +01:00
Permission improvement
This commit is contained in:
parent
76c3ea52ac
commit
90102e1562
@ -9,6 +9,10 @@ import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Representation of a permission granted to a {@link CommandSender}.
|
||||
* Each permission has a string representation used as an identifier, and an optional
|
||||
* {@link NBTCompound} used to store additional data.
|
||||
* <p>
|
||||
* The class is immutable.
|
||||
*/
|
||||
public class Permission {
|
||||
|
||||
|
@ -37,6 +37,15 @@ public interface PermissionHandler {
|
||||
getAllPermissions().remove(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a {@link Permission} based on its string identifier.
|
||||
*
|
||||
* @param permissionName the permission name
|
||||
*/
|
||||
default void removePermission(@NotNull String permissionName) {
|
||||
getAllPermissions().removeIf(permission -> permission.getPermissionName().equals(permissionName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if this handler has the permission {@code permission}.
|
||||
* <p>
|
||||
@ -87,9 +96,7 @@ public interface PermissionHandler {
|
||||
|
||||
if (permission != null) {
|
||||
// Verify using the permission verifier
|
||||
return permissionVerifier != null ?
|
||||
permissionVerifier.isValid(permission.getNBTData()) :
|
||||
true;
|
||||
return permissionVerifier == null || permissionVerifier.isValid(permission.getNBTData());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -65,7 +65,12 @@ public class TestPermissions {
|
||||
player.addPermission(permission1);
|
||||
assertTrue(player.hasPermission("perm.name"));
|
||||
assertTrue(player.hasPermission("perm.name",
|
||||
nbtCompound -> nbtCompound != null && nbtCompound.getString("name").equals("Minestom")));
|
||||
nbtCompound -> {
|
||||
if (nbtCompound != null && nbtCompound.containsKey("name")) {
|
||||
return nbtCompound.getString("name").equals("Minestom");
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
|
||||
player.addPermission(permission2);
|
||||
assertFalse(player.hasPermission("perm.name2", nbtCompound -> nbtCompound != null));
|
||||
|
Loading…
Reference in New Issue
Block a user