Search in sources :

Example 1 with UserUpdateEvent

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);
        }
    }
}
Also used : UserUpdateEvent(io.discloader.discloader.common.event.UserUpdateEvent) User(io.discloader.discloader.core.entity.user.User) IUser(io.discloader.discloader.entity.user.IUser) GuildMemberUpdateEvent(io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent) IUser(io.discloader.discloader.entity.user.IUser) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) PresenceJSON(io.discloader.discloader.network.json.PresenceJSON) IGuild(io.discloader.discloader.entity.guild.IGuild)

Aggregations

UserUpdateEvent (io.discloader.discloader.common.event.UserUpdateEvent)1 GuildMemberUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent)1 User (io.discloader.discloader.core.entity.user.User)1 IGuild (io.discloader.discloader.entity.guild.IGuild)1 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)1 IUser (io.discloader.discloader.entity.user.IUser)1 PresenceJSON (io.discloader.discloader.network.json.PresenceJSON)1