use of io.discloader.discloader.common.event.guild.GuildCreateEvent in project DiscLoader by R3alCl0ud.
the class GuildCreate method handle.
@Override
public void handle(SocketPacket packet) {
Gson gson = new Gson();
String d = gson.toJson(packet.d);
GuildJSON data = gson.fromJson(d, GuildJSON.class);
IGuild guild = null;
if (EntityRegistry.guildExists(data.id))
guild = EntityRegistry.getGuildByID(data.id);
if (guild != null) {
try {
if (!guild.isAvailable() && !data.unavailable) {
guild.setup(data);
if (shouldEmit()) {
GuildCreateEvent event = new GuildCreateEvent(guild);
loader.emit(Events.GUILD_CREATE, event);
loader.emit(event);
}
loader.checkReady();
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
// a brand new guild
guild = EntityRegistry.addGuild(data);
if (this.shouldEmit()) {
GuildCreateEvent event = new GuildCreateEvent(guild);
loader.emit(Events.GUILD_CREATE, event);
loader.emit(event);
}
}
}
Aggregations