Search in sources :

Example 1 with GuildMemberRoleRemoveEvent

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

the class GuildMemberUpdate method handle.

@Override
public void handle(SocketPacket packet) {
    String d = this.gson.toJson(packet.d);
    MemberJSON data = this.gson.fromJson(d, MemberJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    IGuildMember oldMember = guild.getMember(data.user.id), member = gfac.buildMember(guild, data);
    guild.addMember(member);
    if (shouldEmit() && oldMember != null) {
        GuildMemberUpdateEvent event = new GuildMemberUpdateEvent(member, oldMember);
        loader.emit(Events.GUILD_MEMBER_UPDATE, event);
        loader.emit(event);
        if (!member.getNickname().equals(oldMember.getNickname())) {
            loader.emit(new GuildMemberNicknameUpdateEvent(member, oldMember.getNickname()));
        }
        member.getRoles().forEach(role -> {
            if (!oldMember.hasRole(role)) {
                loader.emit(new GuildMemberRoleAddEvent(oldMember, member, role));
            }
        });
        oldMember.getRoles().forEach(role -> {
            if (!member.hasRole(role)) {
                loader.emit(new GuildMemberRoleRemoveEvent(oldMember, member, role));
            }
        });
    // for (member)
    }
}
Also used : GuildMemberUpdateEvent(io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent) GuildMemberRoleAddEvent(io.discloader.discloader.common.event.guild.member.GuildMemberRoleAddEvent) GuildMemberNicknameUpdateEvent(io.discloader.discloader.common.event.guild.member.GuildMemberNicknameUpdateEvent) GuildMemberRoleRemoveEvent(io.discloader.discloader.common.event.guild.member.GuildMemberRoleRemoveEvent) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) IGuild(io.discloader.discloader.entity.guild.IGuild) MemberJSON(io.discloader.discloader.network.json.MemberJSON)

Aggregations

GuildMemberNicknameUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberNicknameUpdateEvent)1 GuildMemberRoleAddEvent (io.discloader.discloader.common.event.guild.member.GuildMemberRoleAddEvent)1 GuildMemberRoleRemoveEvent (io.discloader.discloader.common.event.guild.member.GuildMemberRoleRemoveEvent)1 GuildMemberUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent)1 IGuild (io.discloader.discloader.entity.guild.IGuild)1 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)1 MemberJSON (io.discloader.discloader.network.json.MemberJSON)1