use of io.discloader.discloader.common.event.voice.VoiceStateUpdateEvent 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.asString(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);
}
}
}
Aggregations