Search in sources :

Example 1 with GuildMembersChunkJSON

use of io.discloader.discloader.network.json.GuildMembersChunkJSON in project DiscLoader by R3alCl0ud.

the class GuildMembersChunk method handle.

@Override
public void handle(SocketPacket packet) {
    String d = this.gson.toJson(packet.d);
    GuildMembersChunkJSON data = this.gson.fromJson(d, GuildMembersChunkJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    if (guild == null)
        return;
    Map<Long, IGuildMember> members = new HashMap<>();
    for (MemberJSON m : data.members) {
        IGuildMember member = EntityBuilder.getGuildFactory().buildMember(guild, EntityRegistry.addUser(m.user), new String[] {}, false, false, null);
        guild.addMember(member);
        members.put(member.getID(), member);
    }
    GuildMembersChunkEvent event = new GuildMembersChunkEvent(guild, members);
    loader.emit(event);
}
Also used : HashMap(java.util.HashMap) GuildMembersChunkEvent(io.discloader.discloader.common.event.guild.member.GuildMembersChunkEvent) GuildMembersChunkJSON(io.discloader.discloader.network.json.GuildMembersChunkJSON) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) IGuild(io.discloader.discloader.entity.guild.IGuild) MemberJSON(io.discloader.discloader.network.json.MemberJSON)

Aggregations

GuildMembersChunkEvent (io.discloader.discloader.common.event.guild.member.GuildMembersChunkEvent)1 IGuild (io.discloader.discloader.entity.guild.IGuild)1 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)1 GuildMembersChunkJSON (io.discloader.discloader.network.json.GuildMembersChunkJSON)1 MemberJSON (io.discloader.discloader.network.json.MemberJSON)1 HashMap (java.util.HashMap)1