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()));
}
}
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()));
}
}
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;
}
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);
}
}
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()));
}
}
Aggregations