Search in sources :

Example 1 with GuildVoiceMoveEvent

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

the class Handler method onGuildVoiceMove.

@Override
public void onGuildVoiceMove(GuildVoiceMoveEvent 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> nonBotConnectedMembersInOldChannel = event.getChannelLeft().getMembers().stream().filter(member -> !member.getUser().isBot()).collect(Collectors.toList());
    if (Objects.equals(audioManager.getConnectedChannel(), event.getChannelLeft()) && nonBotConnectedMembersInOldChannel.isEmpty()) {
        closeAudioPlayer(guild, audioManager, defaultVolume);
    }
    List<Member> nonBotConnectedMembers = event.getChannelJoined().getMembers().stream().filter(member -> !member.getUser().isBot()).collect(Collectors.toList());
    if (!nonBotConnectedMembers.isEmpty() && !audioManager.isConnected()) {
        PlayerManager.getInstance().getMusicManager(guild).getAudioPlayer().setVolume(defaultVolume);
        audioManager.openAudioConnection(event.getChannelJoined());
    }
}
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 2 with GuildVoiceMoveEvent

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

the class VoiceModule method onGuildVoiceMove.

@Override
public void onGuildVoiceMove(GuildVoiceMoveEvent event) {
    if (event.getChannelJoined().getParent() != null && !event.getChannelJoined().getParent().equals(getCategory()) && event.getChannelLeft().getParent() != null && event.getChannelLeft().getParent().equals(getCategory())) {
        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().getUniqueId())).forEach(network -> network.remove(player.getPlayer()));
        }
    }
    checkMutedUser(event.getChannelJoined(), event.getMember());
}
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 GuildVoiceMoveEvent

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

the class Main method onGuildVoiceMove.

@Override
public void onGuildVoiceMove(GuildVoiceMoveEvent event) {
    if (event.getChannelJoined().getParent() != null && !event.getChannelJoined().getParent().equals(getCategory()) && event.getChannelLeft().getParent() != null && event.getChannelLeft().getParent().equals(getCategory())) {
        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().getUniqueId())).forEach(network -> network.remove(player.getPlayer()));
        }
    }
    checkMutedUser(event.getChannelJoined(), event.getMember());
}
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)

Example 4 with GuildVoiceMoveEvent

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

the class VoiceModule method onGuildVoiceMove.

@Override
public void onGuildVoiceMove(GuildVoiceMoveEvent event) {
    if (event.getChannelJoined().getParent() != null && !event.getChannelJoined().getParent().equals(getCategory()) && event.getChannelLeft().getParent() != null && event.getChannelLeft().getParent().equals(getCategory())) {
        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().getUniqueId())).forEach(network -> network.remove(player.getPlayer()));
        }
    }
    checkMutedUser(event.getChannelJoined(), event.getMember());
}
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)

Aggregations

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 GuildVoiceLeaveEvent (net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent)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