Search in sources :

Example 1 with GuildMembersChunkEvent

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

the class Guild method fetchMembers.

@Override
public CompletableFuture<Map<Long, IGuildMember>> fetchMembers(int limit) {
    CompletableFuture<Map<Long, IGuildMember>> future = new CompletableFuture<>();
    final Consumer<GuildMembersChunkEvent> consumer = new Consumer<GuildMembersChunkEvent>() {

        @Override
        public void accept(GuildMembersChunkEvent e) {
            if (e.getGuild().getID() != getID()) {
                loader.onceEvent(GuildMembersChunkEvent.class, this);
                return;
            }
            future.complete(e.getMembers());
        }
    };
    loader.onceEvent(GuildMembersChunkEvent.class, consumer);
    Packet payload = new Packet(8, new MemberQuery(limit, ""));
    loader.socket.send(payload);
    return future;
}
Also used : Packet(io.discloader.discloader.entity.sendable.Packet) CompletableFuture(java.util.concurrent.CompletableFuture) Consumer(java.util.function.Consumer) GuildMembersChunkEvent(io.discloader.discloader.common.event.guild.member.GuildMembersChunkEvent) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with GuildMembersChunkEvent

use of io.discloader.discloader.common.event.guild.member.GuildMembersChunkEvent 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)2 HashMap (java.util.HashMap)2 IGuild (io.discloader.discloader.entity.guild.IGuild)1 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)1 Packet (io.discloader.discloader.entity.sendable.Packet)1 GuildMembersChunkJSON (io.discloader.discloader.network.json.GuildMembersChunkJSON)1 MemberJSON (io.discloader.discloader.network.json.MemberJSON)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Consumer (java.util.function.Consumer)1