Search in sources :

Example 1 with GuildVoiceLeaveEvent

use of net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent in project DiscordSRV by DiscordSRV.

the class VoiceModule method onGuildVoiceLeave.

@Override
public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) {
    checkMutedUser(event.getChannelJoined(), event.getMember());
    if (event.getChannelLeft().getParent() == null || !event.getChannelLeft().getParent().equals(getCategory()))
        return;
    UUID uuid = DiscordSRV.getPlugin().getAccountLinkManager().getUuid(event.getMember().getUser().getId());
    if (uuid == null)
        return;
    OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
    if (player.isOnline()) {
        networks.stream().filter(network -> network.contains(player.getPlayer())).forEach(network -> network.remove(player.getPlayer()));
    }
}
Also used : net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) java.util(java.util) Getter(lombok.Getter) Permission(net.dv8tion.jda.api.Permission) VoiceChannelDeleteEvent(net.dv8tion.jda.api.events.channel.voice.VoiceChannelDeleteEvent) GuildVoiceLeaveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent) PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) CompletableFuture(java.util.concurrent.CompletableFuture) DiscordUtil(github.scarsz.discordsrv.util.DiscordUtil) Player(org.bukkit.entity.Player) StringUtils(org.apache.commons.lang3.StringUtils) EventHandler(org.bukkit.event.EventHandler) Pair(net.dv8tion.jda.internal.utils.tuple.Pair) Location(org.bukkit.Location) DiscordSRV(github.scarsz.discordsrv.DiscordSRV) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) GuildVoiceMoveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ListenerAdapter(net.dv8tion.jda.api.hooks.ListenerAdapter) Collectors(java.util.stream.Collectors) OfflinePlayer(org.bukkit.OfflinePlayer) Debug(github.scarsz.discordsrv.Debug) TimeUnit(java.util.concurrent.TimeUnit) GuildVoiceJoinEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent) PlayerUtil(github.scarsz.discordsrv.util.PlayerUtil) EventPriority(org.bukkit.event.EventPriority) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) NumberConversions(org.bukkit.util.NumberConversions) NotNull(org.jetbrains.annotations.NotNull) OfflinePlayer(org.bukkit.OfflinePlayer)

Example 2 with GuildVoiceLeaveEvent

use of net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent in project DiscordSRV by Scarsz.

the class VoiceModule method onGuildVoiceLeave.

@Override
public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) {
    checkMutedUser(event.getChannelJoined(), event.getMember());
    if (event.getChannelLeft().getParent() == null || !event.getChannelLeft().getParent().equals(getCategory()))
        return;
    UUID uuid = DiscordSRV.getPlugin().getAccountLinkManager().getUuid(event.getMember().getUser().getId());
    if (uuid == null)
        return;
    OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
    if (player.isOnline()) {
        networks.stream().filter(network -> network.contains(player.getPlayer())).forEach(network -> network.remove(player.getPlayer()));
    }
}
Also used : net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) java.util(java.util) Getter(lombok.Getter) Permission(net.dv8tion.jda.api.Permission) VoiceChannelDeleteEvent(net.dv8tion.jda.api.events.channel.voice.VoiceChannelDeleteEvent) GuildVoiceLeaveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent) PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) CompletableFuture(java.util.concurrent.CompletableFuture) DiscordUtil(github.scarsz.discordsrv.util.DiscordUtil) Player(org.bukkit.entity.Player) StringUtils(org.apache.commons.lang3.StringUtils) EventHandler(org.bukkit.event.EventHandler) Pair(net.dv8tion.jda.internal.utils.tuple.Pair) Location(org.bukkit.Location) DiscordSRV(github.scarsz.discordsrv.DiscordSRV) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) GuildVoiceMoveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ListenerAdapter(net.dv8tion.jda.api.hooks.ListenerAdapter) Collectors(java.util.stream.Collectors) OfflinePlayer(org.bukkit.OfflinePlayer) Debug(github.scarsz.discordsrv.Debug) TimeUnit(java.util.concurrent.TimeUnit) GuildVoiceJoinEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent) PlayerUtil(github.scarsz.discordsrv.util.PlayerUtil) EventPriority(org.bukkit.event.EventPriority) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) NumberConversions(org.bukkit.util.NumberConversions) NotNull(org.jetbrains.annotations.NotNull) OfflinePlayer(org.bukkit.OfflinePlayer)

Example 3 with GuildVoiceLeaveEvent

use of net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent in project JDA by DV8FromTheWorld.

the class GuildMemberRemoveHandler method handleInternally.

@Override
protected Long handleInternally(DataObject content) {
    final long id = content.getLong("guild_id");
    boolean setup = getJDA().getGuildSetupController().onRemoveMember(id, content);
    if (setup)
        return null;
    GuildImpl guild = (GuildImpl) getJDA().getGuildsView().get(id);
    if (guild == null) {
        // We probably just left the guild and this event is trying to remove us from the guild, therefore ignore
        return null;
    }
    final long userId = content.getObject("user").getUnsignedLong("id");
    if (userId == getJDA().getSelfUser().getIdLong()) {
        // We probably just left the guild and this event is trying to remove us from the guild, therefore ignore
        return null;
    }
    // Update the memberCount
    guild.onMemberRemove();
    CacheView.SimpleCacheView<MemberPresenceImpl> presences = guild.getPresenceView();
    if (presences != null)
        presences.remove(userId);
    User user = api.getEntityBuilder().createUser(content.getObject("user"));
    MemberImpl member = (MemberImpl) guild.getMembersView().remove(userId);
    if (member == null) {
        // WebSocketClient.LOG.debug("Received GUILD_MEMBER_REMOVE for a Member that does not exist in the specified Guild. UserId: {} GuildId: {}", userId, id);
        // Remove user from voice channel if applicable
        guild.getVoiceChannelsView().forEachUnordered((channel) -> {
            VoiceChannelImpl impl = (VoiceChannelImpl) channel;
            Member connected = impl.getConnectedMembersMap().remove(userId);
            if (// user left channel!
            connected != null) {
                getJDA().handleEvent(new GuildVoiceLeaveEvent(getJDA(), responseNumber, connected, channel));
            }
        });
        // Fire cache independent event, we can still inform the library user about the member removal
        getJDA().handleEvent(new GuildMemberRemoveEvent(getJDA(), responseNumber, guild, user, null));
        return null;
    }
    GuildVoiceStateImpl voiceState = (GuildVoiceStateImpl) member.getVoiceState();
    if (// If this user was in an AudioChannel, fire VoiceLeaveEvent.
    voiceState != null && voiceState.inAudioChannel()) {
        AudioChannel channel = voiceState.getChannel();
        voiceState.setConnectedChannel(null);
        ((AudioChannelMixin<?>) channel).getConnectedMembersMap().remove(userId);
        getJDA().handleEvent(new GuildVoiceLeaveEvent(getJDA(), responseNumber, member, channel));
    }
    // The user is not in a different guild that we share
    SnowflakeCacheViewImpl<User> userView = getJDA().getUsersView();
    try (UnlockHook hook = userView.writeLock()) {
        if (// don't remove selfUser from cache
        userId != getJDA().getSelfUser().getIdLong() && getJDA().getGuildsView().stream().noneMatch(g -> g.getMemberById(userId) != null)) {
            userView.remove(userId);
            getJDA().getEventCache().clear(EventCache.Type.USER, userId);
        }
    }
    // Cache independent event
    getJDA().handleEvent(new GuildMemberRemoveEvent(getJDA(), responseNumber, guild, user, member));
    return null;
}
Also used : GuildVoiceLeaveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent) AudioChannel(net.dv8tion.jda.api.entities.AudioChannel) GuildMemberRemoveEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent) UnlockHook(net.dv8tion.jda.internal.utils.UnlockHook) net.dv8tion.jda.internal.entities(net.dv8tion.jda.internal.entities) JDAImpl(net.dv8tion.jda.internal.JDAImpl) CacheView(net.dv8tion.jda.api.utils.cache.CacheView) GuildVoiceLeaveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent) Member(net.dv8tion.jda.api.entities.Member) DataObject(net.dv8tion.jda.api.utils.data.DataObject) User(net.dv8tion.jda.api.entities.User) AudioChannelMixin(net.dv8tion.jda.internal.entities.mixin.channel.middleman.AudioChannelMixin) SnowflakeCacheViewImpl(net.dv8tion.jda.internal.utils.cache.SnowflakeCacheViewImpl) User(net.dv8tion.jda.api.entities.User) AudioChannel(net.dv8tion.jda.api.entities.AudioChannel) CacheView(net.dv8tion.jda.api.utils.cache.CacheView) UnlockHook(net.dv8tion.jda.internal.utils.UnlockHook) GuildMemberRemoveEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent) Member(net.dv8tion.jda.api.entities.Member)

Example 4 with GuildVoiceLeaveEvent

use of net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent in project toby-bot by ml404.

the class Handler method onGuildVoiceLeave.

// Auto leaving voice channel when it becomes empty
@Override
public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) {
    Guild guild = event.getGuild();
    AudioManager audioManager = guild.getAudioManager();
    String volumePropertyName = ConfigDto.Configurations.VOLUME.getConfigValue();
    ConfigDto databaseConfig = configService.getConfigByName(volumePropertyName, event.getGuild().getId());
    int defaultVolume = databaseConfig != null ? Integer.parseInt(databaseConfig.getValue()) : 100;
    List<Member> nonBotConnectedMembers = event.getChannelLeft().getMembers().stream().filter(member -> !member.getUser().isBot()).collect(Collectors.toList());
    if (Objects.equals(audioManager.getConnectedChannel(), event.getChannelLeft()) && nonBotConnectedMembers.isEmpty()) {
        closeAudioPlayer(guild, audioManager, defaultVolume);
    }
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) MusicPlayerHelper.playUserIntro(toby.helpers.MusicPlayerHelper.playUserIntro) JDA(net.dv8tion.jda.api.JDA) BotMain(toby.BotMain) UserDto(toby.jpa.dto.UserDto) AudioManager(net.dv8tion.jda.api.managers.AudioManager) LoggerFactory(org.slf4j.LoggerFactory) Configurable(org.springframework.beans.factory.annotation.Configurable) Autowired(org.springframework.beans.factory.annotation.Autowired) GuildVoiceLeaveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent) EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) ReadyEvent(net.dv8tion.jda.api.events.ReadyEvent) ConfigDto(toby.jpa.dto.ConfigDto) Service(org.springframework.stereotype.Service) Nonnull(javax.annotation.Nonnull) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) Logger(org.slf4j.Logger) Emotes(toby.emote.Emotes) GuildVoiceMoveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent) ListenerAdapter(net.dv8tion.jda.api.hooks.ListenerAdapter) GuildMusicManager(toby.lavaplayer.GuildMusicManager) CommandManager(toby.managers.CommandManager) Collectors(java.util.stream.Collectors) PlayerManager(toby.lavaplayer.PlayerManager) Objects(java.util.Objects) toby.jpa.service(toby.jpa.service) GuildVoiceJoinEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent) List(java.util.List) MessageReceivedEvent(net.dv8tion.jda.api.events.message.MessageReceivedEvent) AudioManager(net.dv8tion.jda.api.managers.AudioManager) ConfigDto(toby.jpa.dto.ConfigDto)

Example 5 with GuildVoiceLeaveEvent

use of net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent in project skoice by carlodrift.

the class Main method onGuildVoiceLeave.

@Override
public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) {
    checkMutedUser(event.getChannelJoined(), event.getMember());
    if (event.getChannelLeft().getParent() == null || !event.getChannelLeft().getParent().equals(getCategory()))
        return;
    UUID uuid = getUniqueId(event.getMember());
    if (uuid == null)
        return;
    OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
    if (player.isOnline()) {
        networks.stream().filter(network -> network.contains(player.getPlayer())).forEach(network -> network.remove(player.getPlayer()));
    }
}
Also used : LoginException(javax.security.auth.login.LoginException) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) java.util(java.util) JDA(net.dv8tion.jda.api.JDA) Permission(net.dv8tion.jda.api.Permission) VoiceChannelDeleteEvent(net.dv8tion.jda.api.events.channel.voice.VoiceChannelDeleteEvent) GuildVoiceLeaveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent) PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) CompletableFuture(java.util.concurrent.CompletableFuture) Player(org.bukkit.entity.Player) StringUtils(org.apache.commons.lang3.StringUtils) GatewayIntent(net.dv8tion.jda.api.requests.GatewayIntent) EventHandler(org.bukkit.event.EventHandler) Skoice(net.clementraynaud.Skoice) Pair(net.dv8tion.jda.internal.utils.tuple.Pair) Location(org.bukkit.Location) JDABuilder(net.dv8tion.jda.api.JDABuilder) Server(org.bukkit.Server) CacheFlag(net.dv8tion.jda.api.utils.cache.CacheFlag) Method(java.lang.reflect.Method) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) MemberCachePolicy(net.dv8tion.jda.api.utils.MemberCachePolicy) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) CommandSender(org.bukkit.command.CommandSender) GuildVoiceMoveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ListenerAdapter(net.dv8tion.jda.api.hooks.ListenerAdapter) IOException(java.io.IOException) CommandExecutor(org.bukkit.command.CommandExecutor) Collectors(java.util.stream.Collectors) OfflinePlayer(org.bukkit.OfflinePlayer) GuildVoiceJoinEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent) EventPriority(org.bukkit.event.EventPriority) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) Command(org.bukkit.command.Command) NumberConversions(org.bukkit.util.NumberConversions) ChunkingFilter(net.dv8tion.jda.api.utils.ChunkingFilter) NotNull(org.jetbrains.annotations.NotNull) OfflinePlayer(org.bukkit.OfflinePlayer)

Aggregations

GuildVoiceLeaveEvent (net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent)5 Collectors (java.util.stream.Collectors)4 net.dv8tion.jda.api.entities (net.dv8tion.jda.api.entities)4 GuildVoiceJoinEvent (net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent)4 GuildVoiceMoveEvent (net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent)4 ListenerAdapter (net.dv8tion.jda.api.hooks.ListenerAdapter)4 java.util (java.util)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 Permission (net.dv8tion.jda.api.Permission)3 VoiceChannelDeleteEvent (net.dv8tion.jda.api.events.channel.voice.VoiceChannelDeleteEvent)3 Pair (net.dv8tion.jda.internal.utils.tuple.Pair)3 StringUtils (org.apache.commons.lang3.StringUtils)3 Bukkit (org.bukkit.Bukkit)3 Location (org.bukkit.Location)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 Player (org.bukkit.entity.Player)3 EventHandler (org.bukkit.event.EventHandler)3 EventPriority (org.bukkit.event.EventPriority)3