Search in sources :

Example 1 with ShutdownEvent

use of net.dv8tion.jda.core.events.ShutdownEvent in project FredBoat by Frederikam.

the class ShardReviveHandler method onShutdown.

@Override
public void onShutdown(ShutdownEvent event) {
    try {
        List<Long> channels = new ArrayList<>();
        int shardId = event.getJDA().getShardInfo().getShardId();
        playerRegistry.getPlayingPlayers().stream().filter(guildPlayer -> DiscordUtil.getShardId(guildPlayer.getGuildId(), credentials) == shardId).forEach(guildPlayer -> {
            VoiceChannel channel = guildPlayer.getCurrentVoiceChannel();
            if (channel != null)
                channels.add(channel.getIdLong());
        });
        channelsToRejoin.put(shardId, channels);
    } catch (Exception ex) {
        log.error("Caught exception while saving channels to revive shard {}", event.getJDA().getShardInfo(), ex);
    }
}
Also used : PlayerRegistry(fredboat.audio.player.PlayerRegistry) Credentials(fredboat.config.property.Credentials) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) ShutdownEvent(net.dv8tion.jda.core.events.ShutdownEvent) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ListenerAdapter(net.dv8tion.jda.core.hooks.ListenerAdapter) ArrayList(java.util.ArrayList) AudioConnectionFacade(fredboat.audio.player.AudioConnectionFacade) Component(org.springframework.stereotype.Component) List(java.util.List) GuildPlayer(fredboat.audio.player.GuildPlayer) Map(java.util.Map) DiscordUtil(fredboat.util.DiscordUtil) ReadyEvent(net.dv8tion.jda.core.events.ReadyEvent) ArrayList(java.util.ArrayList) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel)

Aggregations

AudioConnectionFacade (fredboat.audio.player.AudioConnectionFacade)1 GuildPlayer (fredboat.audio.player.GuildPlayer)1 PlayerRegistry (fredboat.audio.player.PlayerRegistry)1 Credentials (fredboat.config.property.Credentials)1 DiscordUtil (fredboat.util.DiscordUtil)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)1 ReadyEvent (net.dv8tion.jda.core.events.ReadyEvent)1 ShutdownEvent (net.dv8tion.jda.core.events.ShutdownEvent)1 ListenerAdapter (net.dv8tion.jda.core.hooks.ListenerAdapter)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Component (org.springframework.stereotype.Component)1