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;
}
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);
}
Aggregations