public class PermissionUtil
extends java.lang.Object
Constructor | Description |
---|---|
PermissionUtil() |
Modifier and Type | Method | Description |
---|---|---|
static boolean |
canInteract(Member issuer,
Emote emote) |
|
static boolean |
canInteract(Member issuer,
Member target) |
Checks if one given Member can interact with a 2nd given Member - in a permission sense (kick/ban/modify perms).
|
static boolean |
canInteract(Member issuer,
Role target) |
Checks if a given Member can interact with a given Role - in a permission sense (kick/ban/modify perms).
|
static boolean |
canInteract(Role issuer,
Role target) |
Checks if one given Role can interact with a 2nd given Role - in a permission sense (kick/ban/modify perms).
|
static boolean |
canInteract(User issuer,
Emote emote,
MessageChannel channel) |
|
static boolean |
canInteract(User issuer,
Emote emote,
MessageChannel channel,
boolean botOverride) |
|
static boolean |
checkPermission(Channel channel,
Member member,
Permission... permissions) |
|
static boolean |
checkPermission(Member member,
Permission... permissions) |
|
static long |
getEffectivePermission(Channel channel,
Member member) |
|
static long |
getEffectivePermission(Channel channel,
Role role) |
|
static long |
getEffectivePermission(Member member) |
|
static long |
getExplicitPermission(Channel channel,
Member member) |
|
static long |
getExplicitPermission(Channel channel,
Role role) |
|
static long |
getExplicitPermission(Member member) |
public static boolean canInteract(Member issuer, Member target)
issuer
- The member that tries to interact with 2nd membertarget
- The member that is the target of the interactionjava.lang.IllegalArgumentException
- if any of the provided parameters is null
or the provided entities are not from the same guildpublic static boolean canInteract(Member issuer, Role target)
issuer
- The member that tries to interact with the roletarget
- The role that is the target of the interactionjava.lang.IllegalArgumentException
- if any of the provided parameters is null
or the provided entities are not from the same guildpublic static boolean canInteract(Role issuer, Role target)
issuer
- The role that tries to interact with 2nd roletarget
- The role that is the target of the interactionjava.lang.IllegalArgumentException
- if any of the provided parameters is null
or the provided entities are not from the same guildpublic static boolean canInteract(Member issuer, Emote emote)
Member
can use the specified Emote
.
If the specified Member is not in the emote's guild or the emote provided is fake this will return false. Otherwise it will check if the emote is restricted to any roles and if that is the case if the Member has one of these.
In the case of an animated
Emote, this will
check if the issuer is the currently logged in account, and then check if the account has
nitro
, and return false if it doesn't.
For other accounts, this method will not take into account whether the emote is animated, as there is
no real way to check if the Member can interact with them.
Note: This is not checking if the issuer owns the Guild or not.
issuer
- The member that tries to interact with the Emoteemote
- The emote that is the target interactionjava.lang.IllegalArgumentException
- if any of the provided parameters is null
or the provided entities are not from the same guildpublic static boolean canInteract(User issuer, Emote emote, MessageChannel channel, boolean botOverride)
issuer
- The user that tries to interact with the Emoteemote
- The emote that is the target interactionchannel
- The MessageChannel this emote should be interacted withinbotOverride
- Whether bots can use non-managed emotes in other guildsjava.lang.IllegalArgumentException
- if any of the provided parameters is null
or the provided entities are not from the same guildpublic static boolean canInteract(User issuer, Emote emote, MessageChannel channel)
issuer
- The user that tries to interact with the Emoteemote
- The emote that is the target interactionchannel
- The MessageChannel this emote should be interacted withinjava.lang.IllegalArgumentException
- if any of the provided parameters is null
or the provided entities are not from the same guildpublic static boolean checkPermission(Member member, Permission... permissions)
Member
has the specified Permissions
in the specified Guild
. This method properly deals with Owner status.
Note: this is based on effective permissions, not literal permissions. If a member has permissions that would
enable them to do something without the literal permission to do it, this will still return true.
Example: If a member has the Permission.ADMINISTRATOR
permission, they will be able to
Permission.MANAGE_SERVER
as well, even without the literal permissions.
member
- The Member
whose permissions are being checked.permissions
- The Permissions
being checked for.Member
effectively has the specified Permissions
.java.lang.IllegalArgumentException
- if any of the provided parameters is nullpublic static boolean checkPermission(Channel channel, Member member, Permission... permissions)
Member
has the specified Permissions
in the specified Channel
. This method properly deals with
PermissionOverrides
and Owner status.
Note: this is based on effective permissions, not literal permissions. If a member has permissions that would
enable them to do something without the literal permission to do it, this will still return true.
Example: If a member has the Permission.ADMINISTRATOR
permission, they will be able to
Permission.MESSAGE_WRITE
in every channel.
member
- The Member
whose permissions are being checked.channel
- The Channel
being checked.permissions
- The Permissions
being checked for.Member
effectively has the specified Permissions
.java.lang.IllegalArgumentException
- if any of the provided parameters is null
or the provided entities are not from the same guildpublic static long getEffectivePermission(Member member)
long
representation of the effective permissions allowed for this Member
in this Guild
. This can be used in conjunction with
Permission.getPermissions(int)
to easily get a list of all
Permissions
that this member has in this Guild
.
This only returns the Guild-level permissions!
member
- The Member
whose permissions are being checked.long
representation of the literal permissions that
this Member
has in this Guild
.java.lang.IllegalArgumentException
- if any of the provided parameters is null
or the provided entities are not from the same guildpublic static long getEffectivePermission(Channel channel, Member member)
long
representation of the effective permissions allowed for this Member
in this Channel
. This can be used in conjunction with
Permission.getPermissions(long)
to easily get a list of all
Permissions
that this member can use in this Channel
.
Role.getPermissionsRaw()
.channel
- The Channel
being checked.member
- The Member
whose permissions are being checked.long
representation of the effective permissions that this Member
has in this Channel
.java.lang.IllegalArgumentException
- if any of the provided parameters is null
or the provided entities are not from the same guildpublic static long getEffectivePermission(Channel channel, Role role)
long
representation of the effective permissions allowed for this Role
in this Channel
. This can be used in conjunction with
Permission.getPermissions(long)
to easily get a list of all
Permissions
that this role can use in this Channel
.channel
- The Channel
in which permissions are being checked.role
- The Role
whose permissions are being checked.long
representation of the effective permissions that this Role
has in this Channel
java.lang.IllegalArgumentException
- if any of the provided parameters is null
or the provided entities are not from the same guildpublic static long getExplicitPermission(Member member)
Member
in its hosting Guild
.
All permissions returned are explicitly granted to this Member via its Roles
.
Permissions like Permission.ADMINISTRATOR
do not
grant other permissions in this value.
member
- The non-null Member
for which to get implicit permissionsjava.lang.IllegalArgumentException
- If the specified member is null
public static long getExplicitPermission(Channel channel, Member member)
Member
in its hosting Guild
and specific Channel
.
PermissionOverrides
!
All permissions returned are explicitly granted to this Member via its Roles
.
Permissions like Permission.ADMINISTRATOR
do not
grant other permissions in this value.
This factor in all PermissionOverrides
that affect this member
and only grants the ones that are explicitly given.
channel
- The target channel of which to check PermissionOverrides
member
- The non-null Member
for which to get implicit permissionsjava.lang.IllegalArgumentException
- If any of the arguments is null
or the specified entities are not from the same Guild
public static long getExplicitPermission(Channel channel, Role role)
Role
in its hosting Guild
and specific Channel
.
PermissionOverrides
!
All permissions returned are explicitly granted to this Role.
Permissions like Permission.ADMINISTRATOR
do not
grant other permissions in this value.
This factor in existing PermissionOverrides
if possible.
channel
- The target channel of which to check PermissionOverrides
role
- The non-null Role
for which to get implicit permissionsjava.lang.IllegalArgumentException
- If any of the arguments is null
or the specified entities are not from the same Guild