Package net.minestom.server.permission
Interface PermissionHandler
- All Known Subinterfaces:
CommandSender
- All Known Implementing Classes:
ConsoleSender
,Entity
,EntityCreature
,EntityProjectile
,ExperienceOrb
,ItemEntity
,LivingEntity
,Player
,PlayerProjectile
,ServerSender
public interface PermissionHandler
Represents an object which can have permissions.
Permissions are in-memory only by default.
You have however the capacity to store them persistently as the Permission
object
is serializer-friendly, Permission.getPermissionName()
being a String
and Permission.getNBTData()
serializable into a string using NBTCompound.toSNBT()
and deserialized back with SNBTParser.parse()
.
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
addPermission
(@NotNull Permission permission) Adds aPermission
to this handler.@NotNull Set
<Permission> Returns all permissions associated to this handler.default @Nullable Permission
getPermission
(@NotNull String permissionName) Gets thePermission
with the namepermissionName
.default boolean
hasPermission
(@NotNull String permissionName) Gets if this handler has the permission with the namepermissionName
.default boolean
hasPermission
(@NotNull String permissionName, @Nullable PermissionVerifier permissionVerifier) Gets if this handler has the permission with the namepermissionName
and which verify the optionalPermissionVerifier
.default boolean
hasPermission
(@NotNull Permission permission) Gets if this handler has the permissionpermission
.default void
removePermission
(@NotNull String permissionName) Removes aPermission
based on its string identifier.default void
removePermission
(@NotNull Permission permission) Removes aPermission
from this handler.
-
Method Details
-
getAllPermissions
Returns all permissions associated to this handler. The returned collection should be modified only by subclasses.- Returns:
- the permissions of this handler.
-
addPermission
Adds aPermission
to this handler.- Parameters:
permission
- the permission to add
-
removePermission
Removes aPermission
from this handler.- Parameters:
permission
- the permission to remove
-
removePermission
Removes aPermission
based on its string identifier.- Parameters:
permissionName
- the permission name
-
hasPermission
Gets if this handler has the permissionpermission
. This method will also pattern match for wildcards. For example, if this handler has the permission"*"
, this method will always return true. However, if this handler has the permission"foo.b*r.baz"
, this method will return true ifpermission
is"foo.baaar.baz"
or"foo.br.baz
, but not"foo.bar.bz"
.Uses
Permission.equals(Object)
internally.- Parameters:
permission
- the permission to check- Returns:
- true if the handler has the permission, false otherwise
-
getPermission
Gets thePermission
with the namepermissionName
.Useful if you want to retrieve the permission data.
- Parameters:
permissionName
- the permission name- Returns:
- the permission from its name, null if not found
-
hasPermission
default boolean hasPermission(@NotNull @NotNull String permissionName, @Nullable @Nullable PermissionVerifier permissionVerifier) Gets if this handler has the permission with the namepermissionName
and which verify the optionalPermissionVerifier
.- Parameters:
permissionName
- the permission namepermissionVerifier
- the optional verifier, null means that only the permission name will be used- Returns:
- true if the handler has the permission, false otherwise
-
hasPermission
Gets if this handler has the permission with the namepermissionName
.- Parameters:
permissionName
- the permission name- Returns:
- true if the handler has the permission, false otherwise
-