use of org.javacord.core.event.channel.server.voice.ServerVoiceChannelChangeBitrateEventImpl in project Javacord by BtoBastian.
the class ChannelUpdateHandler method handleServerVoiceChannel.
/**
* Handles a server voice channel update.
*
* @param jsonChannel The channel data.
*/
private void handleServerVoiceChannel(JsonNode jsonChannel) {
long channelId = jsonChannel.get("id").asLong();
Optional<ServerVoiceChannel> optionalChannel = api.getServerVoiceChannelById(channelId);
if (!optionalChannel.isPresent()) {
LoggerUtil.logMissingChannel(logger, channelId);
return;
}
ServerVoiceChannelImpl channel = (ServerVoiceChannelImpl) optionalChannel.get();
int oldBitrate = channel.getBitrate();
int newBitrate = jsonChannel.get("bitrate").asInt();
if (oldBitrate != newBitrate) {
channel.setBitrate(newBitrate);
ServerVoiceChannelChangeBitrateEvent event = new ServerVoiceChannelChangeBitrateEventImpl(channel, newBitrate, oldBitrate);
api.getEventDispatcher().dispatchServerVoiceChannelChangeBitrateEvent((DispatchQueueSelector) channel.getServer(), channel.getServer(), channel, event);
}
int oldUserLimit = channel.getUserLimit().orElse(0);
int newUserLimit = jsonChannel.get("user_limit").asInt();
if (oldUserLimit != newUserLimit) {
channel.setUserLimit(newUserLimit);
ServerVoiceChannelChangeUserLimitEvent event = new ServerVoiceChannelChangeUserLimitEventImpl(channel, newUserLimit, oldUserLimit);
api.getEventDispatcher().dispatchServerVoiceChannelChangeUserLimitEvent((DispatchQueueSelector) channel.getServer(), channel.getServer(), channel, event);
}
}
Aggregations