Search in sources :

Example 1 with GuildCreateEvent

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);
        }
    }
}
Also used : GuildCreateEvent(io.discloader.discloader.common.event.guild.GuildCreateEvent) Gson(com.google.gson.Gson) GuildJSON(io.discloader.discloader.network.json.GuildJSON) IGuild(io.discloader.discloader.entity.guild.IGuild)

Aggregations

Gson (com.google.gson.Gson)1 GuildCreateEvent (io.discloader.discloader.common.event.guild.GuildCreateEvent)1 IGuild (io.discloader.discloader.entity.guild.IGuild)1 GuildJSON (io.discloader.discloader.network.json.GuildJSON)1