src/main/java/tracer/util/PermissionComputer.java
/**
     * @param basePermissions base permissions, see computeBasePermissions
     * @param member Member to compute permissions for
     * @param channel Channel to retrieve overrides from
     * @return permissions long with computed base & channel specific overrides
     */
@param basePermissions base permissions, see computeBasePermissions
@param member Member to compute permissions for
@param channel Channel to retrieve overrides from
@return permissions long with computed base & channel specific overrides
@param basePermissions base permissions see computeBasePermissions @param member Member to compute permissions for @param channel Channel to retrieve overrides from @return permissions long with computed base & channel specific overrides
private static long computeOverrides(long basePermissions, @Nonnull Member member, @Nonnull TextChannel channel) {
        if ((basePermissions & Permission.ADMINISTRATOR.getRawValue()) == Permission.ADMINISTRATOR.getRawValue()) {
            return Permission.ALL_PERMISSIONS;
        }
        long permissions = basePermissions;
        {
            PermissionOverride everyoneOverride = channel.getPermissionOverride(channel.getGuild().getPublicRole());
            if (everyoneOverride != null) {
                permissions &= ~everyoneOverride.getDeniedRaw();
                permissions |= everyoneOverride.getAllowedRaw();
            }
        }
        {
            long allowed = 0, denied = 0;
            for (Role role : member.getRoles()) {
                PermissionOverride roleOverride = channel.getPermissionOverride(role);
                if (roleOverride != null) {
                    allowed |= roleOverride.getAllowedRaw();
                    denied |= roleOverride.getDeniedRaw();
                }
            }
            permissions &= ~denied;
            permissions |= allowed;
        }
        {
            PermissionOverride memberOverride = channel.getPermissionOverride(member);
            if (memberOverride != null) {
                permissions &= ~memberOverride.getDeniedRaw();
                permissions |= memberOverride.getAllowedRaw();
            }
        }
        return permissions;
    }
private static long computeOverrides ( long basePermissions , @ Nonnull Member member , @ Nonnull TextChannel channel ) { if ( ( basePermissions & Permission . ADMINISTRATOR . getRawValue ( ) ) == Permission . ADMINISTRATOR . getRawValue ( ) ) { return Permission . ALL_PERMISSIONS ; } long permissions = basePermissions ; { PermissionOverride everyoneOverride = channel . getPermissionOverride ( channel . getGuild ( ) . getPublicRole ( ) ) ; if ( everyoneOverride != null ) { permissions &= ~ everyoneOverride . getDeniedRaw ( ) ; permissions |= everyoneOverride . getAllowedRaw ( ) ; } } { long allowed = 0 , denied = 0 ; for ( Role role : member . getRoles ( ) ) { PermissionOverride roleOverride = channel . getPermissionOverride ( role ) ; if ( roleOverride != null ) { allowed |= roleOverride . getAllowedRaw ( ) ; denied |= roleOverride . getDeniedRaw ( ) ; } } permissions &= ~ denied ; permissions |= allowed ; } { PermissionOverride memberOverride = channel . getPermissionOverride ( member ) ; if ( memberOverride != null ) { permissions &= ~ memberOverride . getDeniedRaw ( ) ; permissions |= memberOverride . getAllowedRaw ( ) ; } } return permissions ; }
@param basePermissions base permissions, see computeBasePermissions
 @param member Member to compute permissions for
 @param channel Channel to retrieve overrides from
 @return permissions long with computed base & channel specific overrides
@param basePermissions base permissions see computeBasePermissions @param member Member to compute permissions for @param channel Channel to retrieve overrides from @return permissions long with computed base & channel specific overrides
// Administrator overrides everything, so just return that. // Everyone overrides // Get the @everyone role override for the channel // pass permissions the given denied and allowed permissions // Role Overrides // for every role add allowed and denied permissions // Add member specific override