use of org.javacord.core.event.user.UserChangeSelfDeafenedEventImpl in project Javacord by BtoBastian.
the class VoiceStateUpdateHandler method handleServerVoiceChannel.
private void handleServerVoiceChannel(JsonNode packet, long userId) {
api.getPossiblyUnreadyServerById(packet.get("guild_id").asLong()).map(ServerImpl.class::cast).ifPresent(server -> {
Member member = new MemberImpl(api, server, packet.get("member"), null);
Optional<ServerVoiceChannelImpl> oldChannel = server.getConnectedVoiceChannel(userId).map(ServerVoiceChannelImpl.class::cast);
Optional<ServerVoiceChannelImpl> newChannel;
if (packet.hasNonNull("channel_id")) {
newChannel = server.getVoiceChannelById(packet.get("channel_id").asLong()).map(ServerVoiceChannelImpl.class::cast);
} else {
newChannel = Optional.empty();
}
if (!newChannel.equals(oldChannel)) {
oldChannel.ifPresent(channel -> {
channel.removeConnectedUser(userId);
dispatchServerVoiceChannelMemberLeaveEvent(member, newChannel.orElse(null), channel, server);
});
newChannel.ifPresent(channel -> {
channel.addConnectedUser(userId);
dispatchServerVoiceChannelMemberJoinEvent(member, channel, oldChannel.orElse(null), server);
});
}
if (!packet.hasNonNull("member")) {
logger.warn("Received VOICE_STATE_UPDATE packet without non-null member field: {}", packet);
return;
}
MemberImpl newMember = new MemberImpl(api, server, packet.get("member"), null);
Member oldMember = server.getRealMemberById(packet.get("user_id").asLong()).orElse(null);
boolean newSelfMuted = packet.get("self_mute").asBoolean();
boolean oldSelfMuted = server.isSelfMuted(userId);
if (newSelfMuted != oldSelfMuted) {
UserChangeSelfMutedEventImpl event = new UserChangeSelfMutedEventImpl(newMember, oldMember);
api.getEventDispatcher().dispatchUserChangeSelfMutedEvent(server, server, newMember.getUser(), event);
}
boolean newSelfDeafened = packet.get("self_deaf").asBoolean();
boolean oldSelfDeafened = server.isSelfDeafened(userId);
if (newSelfDeafened != oldSelfDeafened) {
UserChangeSelfDeafenedEventImpl event = new UserChangeSelfDeafenedEventImpl(newMember, oldMember);
api.getEventDispatcher().dispatchUserChangeSelfDeafenedEvent(server, server, newMember.getUser(), event);
}
boolean newMuted = packet.get("mute").asBoolean();
boolean oldMuted = server.isMuted(userId);
if (newMuted != oldMuted) {
server.setMuted(userId, newMuted);
UserChangeMutedEventImpl event = new UserChangeMutedEventImpl(newMember, oldMember);
api.getEventDispatcher().dispatchUserChangeMutedEvent(server, server, newMember.getUser(), event);
}
boolean newDeafened = packet.get("deaf").asBoolean();
boolean oldDeafened = server.isDeafened(userId);
if (newDeafened != oldDeafened) {
server.setDeafened(userId, newDeafened);
UserChangeDeafenedEventImpl event = new UserChangeDeafenedEventImpl(newMember, oldMember);
api.getEventDispatcher().dispatchUserChangeDeafenedEvent(server, server, newMember.getUser(), event);
}
});
}
Aggregations