Search in sources :

Example 1 with VoiceSwitchEvent

use of io.discloader.discloader.common.event.guild.member.GuildMemberEvent.VoiceSwitchEvent in project DiscLoader by R3alCl0ud.

the class VoiceStateUpdate method handle.

@Override
public void handle(SocketPacket packet) {
    String d = this.gson.toJson(packet.d);
    VoiceStateJSON data = this.gson.fromJson(d, VoiceStateJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    if (guild.getMember(data.user_id) == null)
        return;
    VoiceState currentState = new VoiceState(data, guild);
    VoiceState oldState = guild.getVoiceStates().get(SnowflakeUtil.parse(data.user_id));
    VoiceConnection connection = EntityRegistry.getVoiceConnectionByID(guild.getID());
    if (connection != null && SnowflakeUtil.toString(loader.user).equals(data.user_id)) {
        connection.setSessionID(data.session_id);
        connection.setStateUpdated(true);
        connection.setVoiceChannel(currentState.channel);
    }
    guild.updateVoiceState(currentState);
    if (shouldEmit()) {
        if (currentState.channel != null && (oldState != null && oldState.channel != null)) {
            loader.emit(new VoiceSwitchEvent(currentState.member, oldState.channel));
        } else if (currentState.channel != null) {
            loader.emit(new VoiceJoinEvent(currentState.member));
        } else if (oldState != null && oldState.channel != null) {
            loader.emit(new VoiceLeaveEvent(currentState.member, oldState.channel));
        }
        if (oldState != null) {
            VoiceStateUpdateEvent event = new VoiceStateUpdateEvent(oldState, currentState);
            loader.emit(event);
        }
    }
}
Also used : VoiceSwitchEvent(io.discloader.discloader.common.event.guild.member.GuildMemberEvent.VoiceSwitchEvent) VoiceConnection(io.discloader.discloader.entity.voice.VoiceConnection) VoiceStateUpdateEvent(io.discloader.discloader.common.event.voice.VoiceStateUpdateEvent) VoiceState(io.discloader.discloader.entity.voice.VoiceState) VoiceLeaveEvent(io.discloader.discloader.common.event.guild.member.GuildMemberEvent.VoiceLeaveEvent) VoiceJoinEvent(io.discloader.discloader.common.event.guild.member.GuildMemberEvent.VoiceJoinEvent) VoiceStateJSON(io.discloader.discloader.network.json.VoiceStateJSON) IGuild(io.discloader.discloader.entity.guild.IGuild)

Aggregations

VoiceJoinEvent (io.discloader.discloader.common.event.guild.member.GuildMemberEvent.VoiceJoinEvent)1 VoiceLeaveEvent (io.discloader.discloader.common.event.guild.member.GuildMemberEvent.VoiceLeaveEvent)1 VoiceSwitchEvent (io.discloader.discloader.common.event.guild.member.GuildMemberEvent.VoiceSwitchEvent)1 VoiceStateUpdateEvent (io.discloader.discloader.common.event.voice.VoiceStateUpdateEvent)1 IGuild (io.discloader.discloader.entity.guild.IGuild)1 VoiceConnection (io.discloader.discloader.entity.voice.VoiceConnection)1 VoiceState (io.discloader.discloader.entity.voice.VoiceState)1 VoiceStateJSON (io.discloader.discloader.network.json.VoiceStateJSON)1