Search in sources :

Example 6 with AudioManagerImpl

use of net.dv8tion.jda.internal.managers.AudioManagerImpl in project JDA by DV8FromTheWorld.

the class AudioWebSocket method locked.

private void locked(Consumer<AudioManagerImpl> consumer) {
    AudioManagerImpl manager = (AudioManagerImpl) guild.getAudioManager();
    MiscUtil.locked(manager.CONNECTION_LOCK, () -> consumer.accept(manager));
}
Also used : AudioManagerImpl(net.dv8tion.jda.internal.managers.AudioManagerImpl)

Example 7 with AudioManagerImpl

use of net.dv8tion.jda.internal.managers.AudioManagerImpl in project JDA by DV8FromTheWorld.

the class GuildImpl method getAudioManager.

@Nonnull
@Override
public AudioManager getAudioManager() {
    if (!getJDA().isIntent(GatewayIntent.GUILD_VOICE_STATES))
        throw new IllegalStateException("Cannot use audio features with disabled GUILD_VOICE_STATES intent!");
    final AbstractCacheView<AudioManager> managerMap = getJDA().getAudioManagersView();
    AudioManager mng = managerMap.get(id);
    if (mng == null) {
        // No previous manager found -> create one
        try (UnlockHook hook = managerMap.writeLock()) {
            GuildImpl cachedGuild = (GuildImpl) getJDA().getGuildById(id);
            if (cachedGuild == null)
                throw new IllegalStateException("Cannot get an AudioManager instance on an uncached Guild");
            mng = managerMap.get(id);
            if (mng == null) {
                mng = new AudioManagerImpl(cachedGuild);
                managerMap.getMap().put(id, mng);
            }
        }
    }
    return mng;
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) AudioManagerImpl(net.dv8tion.jda.internal.managers.AudioManagerImpl) Nonnull(javax.annotation.Nonnull)

Aggregations

AudioManagerImpl (net.dv8tion.jda.internal.managers.AudioManagerImpl)7 AudioManager (net.dv8tion.jda.api.managers.AudioManager)4 GuildImpl (net.dv8tion.jda.internal.entities.GuildImpl)3 UnlockHook (net.dv8tion.jda.internal.utils.UnlockHook)3 AudioChannel (net.dv8tion.jda.api.entities.AudioChannel)2 Guild (net.dv8tion.jda.api.entities.Guild)2 VoiceDispatchInterceptor (net.dv8tion.jda.api.hooks.VoiceDispatchInterceptor)2 TLongSet (gnu.trove.set.TLongSet)1 OffsetDateTime (java.time.OffsetDateTime)1 Nonnull (javax.annotation.Nonnull)1 ConnectionListener (net.dv8tion.jda.api.audio.hooks.ConnectionListener)1 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)1 GuildLeaveEvent (net.dv8tion.jda.api.events.guild.GuildLeaveEvent)1 GuildUnavailableEvent (net.dv8tion.jda.api.events.guild.GuildUnavailableEvent)1 DataObject (net.dv8tion.jda.api.utils.data.DataObject)1 JDAImpl (net.dv8tion.jda.internal.JDAImpl)1 AudioConnection (net.dv8tion.jda.internal.audio.AudioConnection)1 GuildVoiceStateImpl (net.dv8tion.jda.internal.entities.GuildVoiceStateImpl)1 MemberImpl (net.dv8tion.jda.internal.entities.MemberImpl)1 AudioChannelMixin (net.dv8tion.jda.internal.entities.mixin.channel.middleman.AudioChannelMixin)1