Search in sources :

Example 1 with ServerVoiceChannelChangeBitrateEventImpl

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);
    }
}
Also used : ServerVoiceChannelChangeBitrateEvent(org.javacord.api.event.channel.server.voice.ServerVoiceChannelChangeBitrateEvent) ServerVoiceChannelChangeUserLimitEvent(org.javacord.api.event.channel.server.voice.ServerVoiceChannelChangeUserLimitEvent) ServerVoiceChannelChangeBitrateEventImpl(org.javacord.core.event.channel.server.voice.ServerVoiceChannelChangeBitrateEventImpl) ServerVoiceChannelChangeUserLimitEventImpl(org.javacord.core.event.channel.server.voice.ServerVoiceChannelChangeUserLimitEventImpl) ServerVoiceChannel(org.javacord.api.entity.channel.ServerVoiceChannel) ServerVoiceChannelImpl(org.javacord.core.entity.channel.ServerVoiceChannelImpl)

Aggregations

ServerVoiceChannel (org.javacord.api.entity.channel.ServerVoiceChannel)1 ServerVoiceChannelChangeBitrateEvent (org.javacord.api.event.channel.server.voice.ServerVoiceChannelChangeBitrateEvent)1 ServerVoiceChannelChangeUserLimitEvent (org.javacord.api.event.channel.server.voice.ServerVoiceChannelChangeUserLimitEvent)1 ServerVoiceChannelImpl (org.javacord.core.entity.channel.ServerVoiceChannelImpl)1 ServerVoiceChannelChangeBitrateEventImpl (org.javacord.core.event.channel.server.voice.ServerVoiceChannelChangeBitrateEventImpl)1 ServerVoiceChannelChangeUserLimitEventImpl (org.javacord.core.event.channel.server.voice.ServerVoiceChannelChangeUserLimitEventImpl)1