diff --git a/src/main/java/net/dv8tion/jda/api/entities/IPermissionHolder.java b/src/main/java/net/dv8tion/jda/api/entities/IPermissionHolder.java index 42b2d54a809..361adfb321a 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/IPermissionHolder.java +++ b/src/main/java/net/dv8tion/jda/api/entities/IPermissionHolder.java @@ -68,8 +68,10 @@ public interface IPermissionHolder extends ISnowflake * If the channel is null * @throws net.dv8tion.jda.api.exceptions.DetachedEntityException * if this is a role and the bot {@link Guild#isDetached() isn't in the guild}. - * @throws UnsupportedOperationException - * if this is a member, the bot {@link Guild#isDetached() isn't in the guild}, and the channel isn't the current interaction's channel. + * @throws net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException + * if this is a member, the bot {@link Guild#isDetached() isn't in the guild}, + * and the combination of Member and GuildChannel doesn't have permission data, + * see {@link net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException MissingEntityInteractionPermissionsException}. * * @return Set of Permissions granted to this Permission Holder in the specified channel. */ @@ -104,8 +106,10 @@ public interface IPermissionHolder extends ISnowflake * If the channel is null * @throws net.dv8tion.jda.api.exceptions.DetachedEntityException * if this is a role and the bot {@link Guild#isDetached() isn't in the guild}. - * @throws UnsupportedOperationException - * if this is a member, the bot {@link Guild#isDetached() isn't in the guild}, and the channel isn't the current interaction's channel. + * @throws net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException + * if this is a member, the bot {@link Guild#isDetached() isn't in the guild}, + * and the combination of Member and GuildChannel doesn't have permission data, + * see {@link net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException MissingEntityInteractionPermissionsException}. * * @return EnumSet of the explicitly granted permissions in the specified channel */ @@ -161,8 +165,10 @@ default boolean hasPermission(@Nonnull Collection permissions) * If null is provided * @throws net.dv8tion.jda.api.exceptions.DetachedEntityException * if this is a role and the bot {@link Guild#isDetached() isn't in the guild}. - * @throws UnsupportedOperationException - * if this is a member, the bot {@link Guild#isDetached() isn't in the guild}, and the channel isn't the current interaction's channel. + * @throws net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException + * if this is a member, the bot {@link Guild#isDetached() isn't in the guild}, + * and the combination of Member and GuildChannel doesn't have permission data, + * see {@link net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException MissingEntityInteractionPermissionsException}. * * @return True, if all of the specified Permissions are granted to this PermissionHolder in the provided GuildChannel. * @@ -183,8 +189,10 @@ default boolean hasPermission(@Nonnull Collection permissions) * If null is provided * @throws net.dv8tion.jda.api.exceptions.DetachedEntityException * if this is a role and the bot {@link Guild#isDetached() isn't in the guild}. - * @throws UnsupportedOperationException - * if this is a member, the bot {@link Guild#isDetached() isn't in the guild}, and the channel isn't the current interaction's channel. + * @throws net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException + * if this is a member, the bot {@link Guild#isDetached() isn't in the guild}, + * and the combination of Member and GuildChannel doesn't have permission data, + * see {@link net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException MissingEntityInteractionPermissionsException}. * * @return True, if all of the specified Permissions are granted to this PermissionHolder in the provided GuildChannel. */ @@ -205,8 +213,10 @@ default boolean hasPermission(@Nonnull GuildChannel channel, @Nonnull Collection * If null is provided * @throws net.dv8tion.jda.api.exceptions.DetachedEntityException * if this is a role and the bot {@link Guild#isDetached() isn't in the guild}. - * @throws UnsupportedOperationException - * if this is a member, the bot {@link Guild#isDetached() isn't in the guild}, and the channel isn't the current interaction's channel. + * @throws net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException + * if this is a member, the bot {@link Guild#isDetached() isn't in the guild}, + * and the combination of Member and GuildChannel doesn't have permission data, + * see {@link net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException MissingEntityInteractionPermissionsException}. * * @return True, if the PermissionHolder has access */ diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/middleman/GuildMessageChannel.java b/src/main/java/net/dv8tion/jda/api/entities/channel/middleman/GuildMessageChannel.java index 302f2a02bae..6d6e33dd441 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/middleman/GuildMessageChannel.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/middleman/GuildMessageChannel.java @@ -65,10 +65,10 @@ default boolean canTalk() * @throws net.dv8tion.jda.api.exceptions.DetachedEntityException * If this channel is a thread, * and the bot {@link net.dv8tion.jda.api.entities.Guild#isDetached() isn't in the guild}. - * @throws UnsupportedOperationException + * @throws net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException * if the bot {@link net.dv8tion.jda.api.entities.Guild#isDetached() isn't in the guild}, - * and this channel isn't the current interaction's channel, - * and the member isn't the current interaction's caller. + * and the combination of the provided Member and this GuildChannel doesn't have permission data, + * see {@link net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException MissingEntityInteractionPermissionsException}. * * @param member * The Member to check diff --git a/src/main/java/net/dv8tion/jda/api/exceptions/MissingEntityInteractionPermissionsException.java b/src/main/java/net/dv8tion/jda/api/exceptions/MissingEntityInteractionPermissionsException.java new file mode 100644 index 00000000000..c4de6bc4dc0 --- /dev/null +++ b/src/main/java/net/dv8tion/jda/api/exceptions/MissingEntityInteractionPermissionsException.java @@ -0,0 +1,54 @@ +/* + * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.dv8tion.jda.api.exceptions; + +/** + * Exception occurring on {@link net.dv8tion.jda.api.entities.detached.IDetachableEntity#isDetached() detached entities}, + * indicating that the permissions could not be checked on this combination of channel and member. + * + *

Getting/Checking the permissions of a {@link net.dv8tion.jda.api.entities.Member Member} in a given {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel GuildChannel}, + * will only work when either: + *

+ */ +public class MissingEntityInteractionPermissionsException extends RuntimeException +{ + /** + * Creates a new MissingEntityInteractionPermissionsException + */ + public MissingEntityInteractionPermissionsException() + { + this("Cannot perform action as the bot is not in the guild"); + } + + /** + * Creates a new MissingEntityInteractionPermissionsException + * + * @param reason + * The reason for this Exception + */ + public MissingEntityInteractionPermissionsException(String reason) + { + super(reason); + } +} diff --git a/src/main/java/net/dv8tion/jda/internal/entities/detached/DetachedMemberImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/detached/DetachedMemberImpl.java index 2f682b2ab22..0c7a7146a83 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/detached/DetachedMemberImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/detached/DetachedMemberImpl.java @@ -24,6 +24,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.entities.channel.unions.DefaultGuildChannelUnion; import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji; +import net.dv8tion.jda.api.exceptions.MissingEntityInteractionPermissionsException; import net.dv8tion.jda.api.requests.restaction.AuditableRestAction; import net.dv8tion.jda.internal.JDAImpl; import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IInteractionPermissionMixin; @@ -270,8 +271,10 @@ private long getRawInteractionPermissions(@Nonnull GuildChannel channel) return channelInteractionPermissions.getPermissions(); } - throw new UnsupportedOperationException("Detached member permissions can only be retrieved in the interaction channel, " + - "and channels only contain the permissions of the interaction caller"); + throw new MissingEntityInteractionPermissionsException( + "Detached member permissions can only be retrieved in the interaction channel, " + + "and channels only contain the permissions of the interaction caller" + ); } @Override