Skip to content

Commit

Permalink
Remove deprecated symbols with deadline 5.1.0 (#2763)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment authored Nov 3, 2024
1 parent 5d9e36c commit 820d56d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 168 deletions.
93 changes: 0 additions & 93 deletions src/main/java/net/dv8tion/jda/api/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
*/
package net.dv8tion.jda.api;

import net.dv8tion.jda.annotations.ForRemoval;
import net.dv8tion.jda.annotations.ReplaceWith;
import net.dv8tion.jda.internal.utils.Checks;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.stream.Collectors;

/**
* Represents the bit offsets used by Discord for Permissions.
Expand Down Expand Up @@ -85,10 +81,6 @@ public enum Permission
VOICE_DEAF_OTHERS( 23, true, true, "Deafen Members"),
VOICE_MOVE_OTHERS( 24, true, true, "Move Members"),
VOICE_USE_VAD( 25, true, true, "Use Voice Activity"),
@Deprecated
@ForRemoval(deadline="5.1.0")
@ReplaceWith("USE_EMBEDDED_ACTIVITIES")
VOICE_START_ACTIVITIES( 39, true, true, "Use Activities"),
VOICE_USE_SOUNDBOARD( 42, true, true, "Use Soundboard"),
VOICE_USE_EXTERNAL_SOUNDS(45, true, true, "Use External Sounds"),
VOICE_SET_STATUS( 48, true, true, "Set Voice Channel Status"),
Expand All @@ -108,63 +100,6 @@ public enum Permission
// This is an optimization suggested by Effective Java 3rd Edition - Item 54
public static final Permission[] EMPTY_PERMISSIONS = new Permission[0];

/**
* Represents a raw set of all permissions
*
* @deprecated To be removed in 5.1.0
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public static final long ALL_PERMISSIONS = Permission.getRaw(Permission.values());

/**
* All permissions that apply to a channel
*
* @deprecated To be removed in 5.1.0 (use {@link Permission#isChannel()} instead)
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public static final long ALL_CHANNEL_PERMISSIONS = Permission.getRaw(Arrays.stream(values())
.filter(Permission::isChannel).collect(Collectors.toSet()));

/**
* All Guild specific permissions which are only available to roles
*
* @deprecated To be removed in 5.1.0 (use {@link Permission#isGuild()} instead)
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public static final long ALL_GUILD_PERMISSIONS = Permission.getRaw(Arrays.stream(values())
.filter(Permission::isGuild).collect(Collectors.toSet()));

/**
* All text channel specific permissions which are only available in text channel permission overrides
*
* @deprecated To be removed in 5.1.0
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public static final long ALL_TEXT_PERMISSIONS
= Permission.getRaw(MESSAGE_ADD_REACTION, MESSAGE_SEND, MESSAGE_TTS, MESSAGE_MANAGE,
MESSAGE_EMBED_LINKS, MESSAGE_ATTACH_FILES, MESSAGE_EXT_EMOJI, MESSAGE_EXT_STICKER,
MESSAGE_HISTORY, MESSAGE_MENTION_EVERYONE,
USE_APPLICATION_COMMANDS, USE_EXTERNAL_APPLICATIONS, USE_EMBEDDED_ACTIVITIES,
MANAGE_THREADS, CREATE_PUBLIC_THREADS, CREATE_PRIVATE_THREADS,
MESSAGE_SEND_IN_THREADS, MESSAGE_ATTACH_VOICE_MESSAGE, MESSAGE_SEND_POLLS);

/**
* All voice channel specific permissions which are only available in voice channel permission overrides
*
* @deprecated To be removed in 5.1.0
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public static final long ALL_VOICE_PERMISSIONS
= Permission.getRaw(VOICE_STREAM, VOICE_CONNECT, VOICE_SPEAK, VOICE_MUTE_OTHERS,
VOICE_DEAF_OTHERS, VOICE_MOVE_OTHERS, VOICE_USE_VAD,
PRIORITY_SPEAKER, REQUEST_TO_SPEAK, USE_EMBEDDED_ACTIVITIES,
VOICE_USE_SOUNDBOARD, VOICE_USE_EXTERNAL_SOUNDS, VOICE_SET_STATUS);

private final int offset;
private final long raw;
private final boolean isGuild, isChannel;
Expand Down Expand Up @@ -235,34 +170,6 @@ public boolean isChannel()
return isChannel;
}

/**
* Whether this permission is specifically for {@link net.dv8tion.jda.api.entities.channel.concrete.TextChannel TextChannels}
*
* @return True, if and only if this permission can only be applied to text channels
*
* @deprecated To be removed in 5.1.0
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public boolean isText()
{
return (raw & ALL_TEXT_PERMISSIONS) == raw;
}

/**
* Whether this permission is specifically for {@link net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel VoiceChannels}
*
* @return True, if and only if this permission can only be applied to voice channels
*
* @deprecated To be removed in 5.1.0
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public boolean isVoice()
{
return (raw & ALL_VOICE_PERMISSIONS) == raw;
}

/**
* Gets the first {@link net.dv8tion.jda.api.Permission Permission} relating to the provided offset.
* <br>If there is no {@link net.dv8tion.jda.api.Permission Permssions} that matches the provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ public interface StageInstanceManager extends Manager<StageInstanceManager>
{
/** Used to reset the topic field */
long TOPIC = 1;
/** Used to reset the privacy level field */
/**
* Used to reset the privacy level field
*
* @deprecated Obsolete.
*/
@Deprecated
@ForRemoval(deadline = "5.3.0")
long PRIVACY_LEVEL = 1 << 1;

/**
Expand Down Expand Up @@ -110,24 +116,4 @@ public interface StageInstanceManager extends Manager<StageInstanceManager>
@Nonnull
@CheckReturnValue
StageInstanceManager setTopic(@Nullable String topic);

/**
* Sets the {@link net.dv8tion.jda.api.entities.StageInstance.PrivacyLevel PrivacyLevel} for this stage instance.
* <br>This indicates whether guild lurkers are allowed to join the stage instance or only guild members.
*
* @param level
* The privacy level
*
* @throws IllegalArgumentException
* If the privacy level is null, {@link net.dv8tion.jda.api.entities.StageInstance.PrivacyLevel#UNKNOWN UNKNOWN}.
*
* @return StageInstanceManager for chaining convenience
*
* @deprecated Obsolete.
*/
@Nonnull
@CheckReturnValue
@Deprecated
@ForRemoval(deadline = "5.1.0")
StageInstanceManager setPrivacyLevel(@Nonnull StageInstance.PrivacyLevel level);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package net.dv8tion.jda.api.requests.restaction;

import net.dv8tion.jda.annotations.ForRemoval;
import net.dv8tion.jda.api.entities.StageInstance;
import net.dv8tion.jda.api.requests.RestAction;

Expand Down Expand Up @@ -63,24 +62,4 @@ public interface StageInstanceAction extends RestAction<StageInstance>
@Nonnull
@CheckReturnValue
StageInstanceAction setTopic(@Nonnull String topic);

/**
* Sets the {@link net.dv8tion.jda.api.entities.StageInstance.PrivacyLevel PrivacyLevel} for the stage instance.
* <br>This indicates whether guild lurkers are allowed to join the stage instance or only guild members.
*
* @param level
* The {@link net.dv8tion.jda.api.entities.StageInstance.PrivacyLevel}
*
* @throws IllegalArgumentException
* If the privacy level is null, {@link net.dv8tion.jda.api.entities.StageInstance.PrivacyLevel#UNKNOWN UNKNOWN}.
*
* @return The StageInstanceAction for chaining
*
* @deprecated Obsolete.
*/
@Nonnull
@CheckReturnValue
@Deprecated
@ForRemoval(deadline = "5.1.0")
StageInstanceAction setPrivacyLevel(@Nonnull StageInstance.PrivacyLevel level);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class StageInstanceManagerImpl extends ManagerBase<StageInstanceManager>
private final StageInstance instance;

private String topic;
private StageInstance.PrivacyLevel privacyLevel;

public StageInstanceManagerImpl(StageInstance instance)
{
Expand Down Expand Up @@ -62,26 +61,12 @@ public StageInstanceManager setTopic(@Nullable String topic)
return this;
}

@Nonnull
@Override
@Deprecated
public StageInstanceManager setPrivacyLevel(@Nonnull StageInstance.PrivacyLevel level)
{
Checks.notNull(level, "PrivacyLevel");
Checks.check(level != StageInstance.PrivacyLevel.UNKNOWN, "PrivacyLevel must not be UNKNOWN!");
this.privacyLevel = level;
set |= PRIVACY_LEVEL;
return this;
}

@Override
protected RequestBody finalizeData()
{
DataObject body = DataObject.empty();
if (shouldUpdate(TOPIC) && topic != null)
body.put("topic", topic);
if (shouldUpdate(PRIVACY_LEVEL))
body.put("privacy_level", privacyLevel.getKey());
return getRequestBody(body);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class StageInstanceActionImpl extends RestActionImpl<StageInstance> imple
{
private final StageChannel channel;
private String topic;
private StageInstance.PrivacyLevel level = StageInstance.PrivacyLevel.GUILD_ONLY;

public StageInstanceActionImpl(StageChannel channel)
{
Expand Down Expand Up @@ -75,24 +74,12 @@ public StageInstanceAction setTopic(@Nonnull String topic)
return this;
}

@Nonnull
@Override
@Deprecated
public StageInstanceAction setPrivacyLevel(@Nonnull StageInstance.PrivacyLevel level)
{
Checks.notNull(level, "PrivacyLevel");
Checks.check(level != StageInstance.PrivacyLevel.UNKNOWN, "The PrivacyLevel must not be UNKNOWN!");
this.level = level;
return this;
}

@Override
protected RequestBody finalizeData()
{
DataObject body = DataObject.empty();
body.put("channel_id", channel.getId());
body.put("topic", topic);
body.put("privacy_level", level.getKey());
return getRequestBody(body);
}

Expand Down
18 changes: 13 additions & 5 deletions src/main/java/net/dv8tion/jda/internal/utils/PermissionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@
import net.dv8tion.jda.internal.entities.GuildImpl;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

public class PermissionUtil
{
private static final long ALL_PERMISSIONS = Permission.getRaw(Permission.values());
private static final long ALL_CHANNEL_PERMISSIONS = Permission.getRaw(
Arrays.stream(Permission.values())
.filter(Permission::isChannel)
.collect(Collectors.toList()));

/**
* Checks if one given Member can interact with a 2nd given Member - in a permission sense (kick/ban/modify perms).
* This only checks the Role-Position and does not check the actual permission (kick/ban/manage_role/...)
Expand Down Expand Up @@ -305,14 +313,14 @@ public static long getEffectivePermission(Member member)
Checks.notNull(member, "Member");

if (member.isOwner())
return Permission.ALL_PERMISSIONS;
return ALL_PERMISSIONS;
//Default to binary OR of all global permissions in this guild
long permission = member.getGuild().getPublicRole().getPermissionsRaw();
for (Role role : member.getRoles())
{
permission |= role.getPermissionsRaw();
if (isApplied(permission, Permission.ADMINISTRATOR.getRawValue()))
return Permission.ALL_PERMISSIONS;
return ALL_PERMISSIONS;
}
// See https://discord.com/developers/docs/topics/permissions#permissions-for-timed-out-members
if (member.isTimedOut())
Expand Down Expand Up @@ -349,13 +357,13 @@ public static long getEffectivePermission(GuildChannel channel, Member member)
if (member.isOwner())
{
// Owner effectively has all permissions
return Permission.ALL_PERMISSIONS;
return ALL_PERMISSIONS;
}

long permission = getEffectivePermission(member);
final long admin = Permission.ADMINISTRATOR.getRawValue();
if (isApplied(permission, admin))
return Permission.ALL_PERMISSIONS;
return ALL_PERMISSIONS;

// MANAGE_CHANNEL allows to delete channels within a category (this is undocumented behavior)
if (channel instanceof ICategorizableChannel) {
Expand Down Expand Up @@ -413,7 +421,7 @@ public static long getEffectivePermission(GuildChannel channel, Role role)

long permissions = getExplicitPermission(channel, role);
if (isApplied(permissions, Permission.ADMINISTRATOR.getRawValue()))
return Permission.ALL_CHANNEL_PERMISSIONS;
return ALL_CHANNEL_PERMISSIONS;
else if (!isApplied(permissions, Permission.VIEW_CHANNEL.getRawValue()))
return 0;
return permissions;
Expand Down

0 comments on commit 820d56d

Please sign in to comment.