use of io.discloader.discloader.common.event.UserUpdateEvent in project DiscLoader by R3alCl0ud.
the class PresenceUpdate method handle.
@Override
public void handle(SocketPacket packet) {
PresenceJSON data = this.gson.fromJson(gson.toJson(packet.d), PresenceJSON.class);
IUser user = EntityRegistry.getUserByID(data.user.id);
if (user == null) {
if (data.user.username != null) {
user = EntityRegistry.addUser(data.user);
} else {
return;
}
}
IUser oldUser = new User(user);
user.setup(data.user);
if (!user.equals(oldUser)) {
UserUpdateEvent event = new UserUpdateEvent(user, oldUser);
loader.emit(DLUtil.Events.USER_UPDATE, event);
loader.emit(event);
}
IGuild guild = data.guild_id == null ? null : EntityRegistry.getGuildByID(data.guild_id);
if (guild != null) {
IGuildMember oldMember = guild.getMember(user.getID()), member;
if (oldMember == null && !data.status.equalsIgnoreCase("offline")) {
member = guild.addMember(user, data.roles, false, false, data.nick, false);
loader.emit(DLUtil.Events.GUILD_MEMBER_AVAILABLE, member);
} else if (oldMember != null) {
member = guild.addMember(user, data.roles, oldMember.isDeafened(), oldMember.isMuted(), data.nick, false);
guild.setPresence(data);
loader.emit(new GuildMemberUpdateEvent(member, oldMember));
} else {
guild.setPresence(data);
}
}
}
Aggregations