Interface IPermissionHolder

  • All Superinterfaces:
    ISnowflake
    All Known Subinterfaces:
    Member, Role

    public interface IPermissionHolder
    extends ISnowflake
    Marker for entities that hold Permissions within JDA
    Since:
    3.0
    See Also:
    Role, Member
    • Method Detail

      • getGuild

        @Nonnull
        Guild getGuild()
        The Guild to which this PermissionHolder is related
        Returns:
        A never-null Guild to which this PermissionHolder is linked
      • getPermissions

        @Nonnull
        java.util.EnumSet<Permission> getPermissions()
        The Guild-Wide Permissions this PermissionHolder holds.
        Changes to the returned set do not affect this entity directly.
        Returns:
        An EnumSet of Permissions granted to this PermissionHolder.
      • getPermissions

        @Nonnull
        java.util.EnumSet<Permission> getPermissions​(@Nonnull
                                                     GuildChannel channel)
        The Permissions this PermissionHolder holds in the specified GuildChannel.
        Permissions returned by this may be different from getPermissions() due to the GuildChannel's PermissionOverrides.
        Changes to the returned set do not affect this entity directly.
        Parameters:
        channel - The GuildChannel of which to get Permissions for
        Returns:
        Set of Permissions granted to this Permission Holder in the specified channel.
        Throws:
        java.lang.IllegalArgumentException - If the channel is null
      • getPermissionsExplicit

        @Nonnull
        java.util.EnumSet<Permission> getPermissionsExplicit()
        The explicitly granted permissions for this permission holder in the guild.
        This disregards owner and administrator privileges. For a role this is identical to getPermissions() and members have all their roles taken into consideration.
        Changes to the returned set do not affect this entity directly.
        Returns:
        EnumSet of the explicitly granted permissions
      • getPermissionsExplicit

        @Nonnull
        java.util.EnumSet<Permission> getPermissionsExplicit​(@Nonnull
                                                             GuildChannel channel)
        The explicitly granted permissions for this permission holder in the guild.
        This disregards owner and administrator privileges.
        Permissions returned by this may be different from getPermissionsExplicit() due to the GuildChannel's PermissionOverrides.
        Changes to the returned set do not affect this entity directly.
        Parameters:
        channel - The GuildChannel of which to get Permissions for
        Returns:
        EnumSet of the explicitly granted permissions in the specified channel
        Throws:
        java.lang.IllegalArgumentException - If the channel is null
      • hasPermission

        boolean hasPermission​(@Nonnull
                              Permission... permissions)
        Checks whether or not this PermissionHolder has the given Permissions in the Guild.
        Parameters:
        permissions - Permissions to check for.
        Returns:
        True, if all of the specified Permissions are granted to this PermissionHolder.
        Throws:
        java.lang.IllegalArgumentException - If null is provided
      • hasPermission

        boolean hasPermission​(@Nonnull
                              java.util.Collection<Permission> permissions)
        Checks whether or not this PermissionHolder has the Permissions in the provided Collection<Permission> in the Guild.
        Parameters:
        permissions - Permissions to check for.
        Returns:
        True, if all of the specified Permissions are granted to this PermissionHolder.
        Throws:
        java.lang.IllegalArgumentException - If null is provided
        See Also:
        EnumSet
      • hasPermission

        boolean hasPermission​(@Nonnull
                              GuildChannel channel,
                              @Nonnull
                              Permission... permissions)
        Checks whether or not this PermissionHolder has the given Permissions in the specified GuildChannel.
        Parameters:
        channel - The GuildChannel in which to check.
        permissions - Permissions to check for.
        Returns:
        True, if all of the specified Permissions are granted to this PermissionHolder in the provided GuildChannel.
        Throws:
        java.lang.IllegalArgumentException - If null is provided
        See Also:
        EnumSet
      • hasPermission

        boolean hasPermission​(@Nonnull
                              GuildChannel channel,
                              @Nonnull
                              java.util.Collection<Permission> permissions)
        Checks whether or not this PermissionHolder has the Permissions in the provided Collection<Permission> in the specified GuildChannel.
        Parameters:
        channel - The GuildChannel in which to check.
        permissions - Permissions to check for.
        Returns:
        True, if all of the specified Permissions are granted to this PermissionHolder in the provided GuildChannel.
        Throws:
        java.lang.IllegalArgumentException - If null is provided
      • hasAccess

        default boolean hasAccess​(@Nonnull
                                  GuildChannel channel)
        Checks whether or not this PermissionHolder has VIEW_CHANNEL and VOICE_CONNECT permissions in the GuildChannel.
        Parameters:
        channel - The channel to check access for
        Returns:
        True, if the PermissionHolder has access
        Throws:
        java.lang.IllegalArgumentException - If null is provided
      • canSync

        boolean canSync​(@Nonnull
                        GuildChannel targetChannel,
                        @Nonnull
                        GuildChannel syncSource)
        Whether the permissions of this PermissionHolder are good enough to sync the target channel with the sync source.
        This checks what permissions would be changed by the overrides of the sync source and whether the permission holder is able to set them on the target channel.

        If the permission holder had Permission.MANAGE_PERMISSIONS in an override on the target channel or Permission.ADMINISTRATOR on one of its roles, then it can set any permission on the target channel. Otherwise, the permission holder can only set permissions it also has in the channel.

        Parameters:
        targetChannel - The target channel to check
        syncSource - The sync source, for example the parent category (see GuildChannel.getParent())
        Returns:
        True, if the channels can be synced
        Throws:
        java.lang.IllegalArgumentException - If either of the channels is null or not from the same guild as this permission holder
      • canSync

        boolean canSync​(@Nonnull
                        GuildChannel channel)
        Whether the permissions of this PermissionHolder are good enough to sync the target channel with any other channel.
        This checks whether the permission holder has local administrator.

        If the permission holder had Permission.MANAGE_PERMISSIONS in an override on the target channel or Permission.ADMINISTRATOR on one of its roles, then it can set any permission on the target channel.

        Parameters:
        channel - The target channel to check
        Returns:
        True, if the channel can be synced
        Throws:
        java.lang.IllegalArgumentException - If the channel is null or not from the same guild as this permission holder