Class RoleImpl

java.lang.Object
net.dv8tion.jda.internal.entities.RoleImpl
All Implemented Interfaces:
Comparable<Role>, Formattable, IDetachableEntity, IMentionable, IPermissionHolder, ISnowflake, Role, IDetachableEntityMixin, RoleMixin<RoleImpl>

public class RoleImpl extends Object implements Role, RoleMixin<RoleImpl>
  • Constructor Details

    • RoleImpl

      public RoleImpl(long id, Guild guild)
  • Method Details

    • isDetached

      public boolean isDetached()
      Description copied from interface: IDetachableEntity
      Whether this entity is detached.

      If this returns true, this entity cannot be retrieved, will never be updated, and most methods that would otherwise return a RestAction will throw a DetachedEntityException instead.

      Specified by:
      isDetached in interface IDetachableEntity
      Returns:
      True, if the entity is detached
    • getPosition

      public int getPosition()
      Description copied from interface: Role
      The hierarchical position of this Role in the Guild hierarchy. (higher value means higher role).
      The Guild.getPublicRole()'s getPosition() always returns -1.
      Specified by:
      getPosition in interface Role
      Returns:
      The position of this Role as integer.
    • getPositionRaw

      public int getPositionRaw()
      Description copied from interface: Role
      The actual position of the Role as stored and given by Discord.
      Role positions are actually based on a pairing of the creation time (as stored in the snowflake id) and the position. If 2 or more roles share the same position then they are sorted based on their creation date.
      The more recent a role was created, the lower it is in the hierarchy. This is handled by Role.getPosition() and it is most likely the method you want. If, for some reason, you want the actual position of the Role then this method will give you that value.
      Specified by:
      getPositionRaw in interface Role
      Returns:
      The true, Discord stored, position of the Role.
    • getName

      @Nonnull public String getName()
      Description copied from interface: Role
      The Name of this Role.
      Specified by:
      getName in interface Role
      Returns:
      Never-null String containing the name of this Role.
    • isManaged

      public boolean isManaged()
      Description copied from interface: Role
      Whether this Role is managed by an integration
      Specified by:
      isManaged in interface Role
      Returns:
      True, if this Role is managed.
    • isHoisted

      public boolean isHoisted()
      Description copied from interface: Role
      Whether this Role is hoisted
      Members in a hoisted role are displayed in their own grouping on the user-list
      Specified by:
      isHoisted in interface Role
      Returns:
      True, if this Role is hoisted.
    • isMentionable

      public boolean isMentionable()
      Description copied from interface: Role
      Whether or not this Role is mentionable
      Specified by:
      isMentionable in interface Role
      Returns:
      True, if Role is mentionable.
    • getPermissionsRaw

      public long getPermissionsRaw()
      Description copied from interface: Role
      The long representation of the literal permissions that this Role has.
      NOTE: these do not necessarily represent the permissions this role will have in a GuildChannel.
      Specified by:
      getPermissionsRaw in interface Role
      Returns:
      Never-negative long containing offset permissions of this role.
    • getPermissions

      @Nonnull public EnumSet<Permission> getPermissions()
      Description copied from interface: IPermissionHolder
      The Guild-Wide Permissions this PermissionHolder holds.
      Changes to the returned set do not affect this entity directly.
      Specified by:
      getPermissions in interface IPermissionHolder
      Returns:
      An EnumSet of Permissions granted to this PermissionHolder.
    • getPermissions

      @Nonnull public EnumSet<Permission> getPermissions(@Nonnull GuildChannel channel)
      Description copied from interface: IPermissionHolder
      The Permissions this PermissionHolder holds in the specified GuildChannel.
      Permissions returned by this may be different from IPermissionHolder.getPermissions() due to the GuildChannel's PermissionOverrides.
      Changes to the returned set do not affect this entity directly.
      Specified by:
      getPermissions in interface IPermissionHolder
      Parameters:
      channel - The GuildChannel of which to get Permissions for
      Returns:
      Set of Permissions granted to this Permission Holder in the specified channel.
    • getPermissionsExplicit

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

      @Nonnull public EnumSet<Permission> getPermissionsExplicit(@Nonnull GuildChannel channel)
      Description copied from interface: IPermissionHolder
      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 IPermissionHolder.getPermissionsExplicit() due to the GuildChannel's PermissionOverrides.
      Changes to the returned set do not affect this entity directly.
      Specified by:
      getPermissionsExplicit in interface IPermissionHolder
      Parameters:
      channel - The GuildChannel of which to get Permissions for
      Returns:
      EnumSet of the explicitly granted permissions in the specified channel
    • getColor

      public Color getColor()
      Description copied from interface: Role
      The color this Role is displayed in.
      Specified by:
      getColor in interface Role
      Returns:
      Color value of Role-color
      See Also:
    • getColorRaw

      public int getColorRaw()
      Description copied from interface: Role
      The raw color RGB value used for this role
      Defaults to Role.DEFAULT_COLOR_RAW if this role has no set color
      Specified by:
      getColorRaw in interface Role
      Returns:
      The raw RGB color value or default
    • isPublicRole

      public boolean isPublicRole()
      Description copied from interface: Role
      Whether this role is the @everyone role for its Guild, which is assigned to everyone who joins the Guild.
      Specified by:
      isPublicRole in interface Role
      Returns:
      True, if and only if this Role is the public role for the Guild provided by Role.getGuild().
      See Also:
    • hasPermission

      public boolean hasPermission(@Nonnull Permission... permissions)
      Description copied from interface: IPermissionHolder
      Checks whether or not this PermissionHolder has the given Permissions in the Guild.
      Specified by:
      hasPermission in interface IPermissionHolder
      Parameters:
      permissions - Permissions to check for.
      Returns:
      True, if all of the specified Permissions are granted to this PermissionHolder.
    • hasPermission

      public boolean hasPermission(@Nonnull GuildChannel channel, @Nonnull Permission... permissions)
      Description copied from interface: IPermissionHolder
      Checks whether or not this PermissionHolder has the given Permissions in the specified GuildChannel.
      Specified by:
      hasPermission in interface IPermissionHolder
      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.
      See Also:
    • canSync

      public boolean canSync(@Nonnull IPermissionContainer targetChannel, @Nonnull IPermissionContainer syncSource)
      Description copied from interface: IPermissionHolder
      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.

      Specified by:
      canSync in interface IPermissionHolder
      Parameters:
      targetChannel - The target channel to check
      syncSource - The sync source, for example the parent category (see ICategorizableChannel.getParentCategory())
      Returns:
      True, if the channels can be synced
    • canSync

      public boolean canSync(@Nonnull IPermissionContainer channel)
      Description copied from interface: IPermissionHolder
      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.

      Specified by:
      canSync in interface IPermissionHolder
      Parameters:
      channel - The target channel to check
      Returns:
      True, if the channel can be synced
    • canInteract

      public boolean canInteract(@Nonnull Role role)
      Description copied from interface: Role
      Whether this Role can interact with the specified Role. (move/manage/etc.)
      Specified by:
      canInteract in interface Role
      Parameters:
      role - The not-null role to compare to
      Returns:
      True, if this role can interact with the specified role
    • getGuild

      @Nonnull public Guild getGuild()
      Description copied from interface: Role
      Returns the Guild this Role exists in
      Specified by:
      getGuild in interface IPermissionHolder
      Specified by:
      getGuild in interface Role
      Returns:
      the Guild containing this Role
    • getManager

      @Nonnull public RoleManager getManager()
      Description copied from interface: Role
      The RoleManager for this Role. In the RoleManager, you can modify all its values.
      You modify multiple fields in one request by chaining setters before calling RestAction.queue().
      Specified by:
      getManager in interface Role
      Returns:
      The RoleManager of this Role
    • delete

      @Nonnull public AuditableRestAction<Void> delete()
      Description copied from interface: Role
      Deletes this Role.

      Possible ErrorResponses include:

      Specified by:
      delete in interface Role
      Returns:
      RestAction
    • getJDA

      @Nonnull public JDA getJDA()
      Description copied from interface: Role
      Returns the JDA instance of this Role
      Specified by:
      getJDA in interface Role
      Returns:
      the corresponding JDA instance
    • getTags

      @Nonnull public Role.RoleTags getTags()
      Description copied from interface: Role
      The tags of this role.
      This is useful to determine the purpose of a managed role.

      This requires CacheFlag.ROLE_TAGS to be enabled. See JDABuilder.enableCache(...).

      Specified by:
      getTags in interface Role
      Returns:
      Role.RoleTags
    • getIcon

      @Nullable public RoleIcon getIcon()
      Description copied from interface: Role
      The Icon of this role or null if no custom image or emoji is set. This icon will be displayed next to the role's name in the members tab and in chat.
      Specified by:
      getIcon in interface Role
      Returns:
      Possibly-null Icon of this role
    • getAsMention

      @Nonnull public String getAsMention()
      Description copied from interface: IMentionable
      Retrieve a Mention for this Entity. For the public Role (@everyone), this will return the literal string "@everyone".
      Specified by:
      getAsMention in interface IMentionable
      Returns:
      A resolvable mention.
    • getIdLong

      public long getIdLong()
      Description copied from interface: ISnowflake
      The Snowflake id of this entity. This is unique to every entity and will never change.
      Specified by:
      getIdLong in interface ISnowflake
      Returns:
      Long containing the Id.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setName

      public RoleImpl setName(String name)
      Specified by:
      setName in interface RoleMixin<RoleImpl>
    • setColor

      public RoleImpl setColor(int color)
      Specified by:
      setColor in interface RoleMixin<RoleImpl>
    • setManaged

      public RoleImpl setManaged(boolean managed)
      Specified by:
      setManaged in interface RoleMixin<RoleImpl>
    • setHoisted

      public RoleImpl setHoisted(boolean hoisted)
      Specified by:
      setHoisted in interface RoleMixin<RoleImpl>
    • setMentionable

      public RoleImpl setMentionable(boolean mentionable)
      Specified by:
      setMentionable in interface RoleMixin<RoleImpl>
    • setRawPermissions

      public RoleImpl setRawPermissions(long rawPermissions)
      Specified by:
      setRawPermissions in interface RoleMixin<RoleImpl>
    • setRawPosition

      public RoleImpl setRawPosition(int rawPosition)
      Specified by:
      setRawPosition in interface RoleMixin<RoleImpl>
    • setTags

      public RoleImpl setTags(DataObject tags)
      Specified by:
      setTags in interface RoleMixin<RoleImpl>
    • setIcon

      public RoleImpl setIcon(RoleIcon icon)
      Specified by:
      setIcon in interface RoleMixin<RoleImpl>
    • freezePosition

      public void freezePosition()