Search in sources :

Example 1 with ChannelUpdateEvent

use of io.discloader.discloader.common.event.channel.ChannelUpdateEvent in project DiscLoader by R3alCl0ud.

the class ChannelUpdate method handle.

@Override
public void handle(SocketPacket packet) {
    String d = gson.toJson(packet.d);
    ChannelJSON data = gson.fromJson(d, ChannelJSON.class);
    IGuild guild = null;
    IChannel oldChannel = EntityRegistry.getChannelByID(data.id);
    IChannel channel = null;
    if (data.guild_id != null) {
        guild = EntityRegistry.getGuildByID(data.guild_id);
    }
    channel = EntityRegistry.addChannel(data, loader, guild);
    if (oldChannel instanceof ITextChannel) {
        ITextChannel oitc = (ITextChannel) oldChannel, itc = (ITextChannel) channel;
        for (IMessage message : oitc.getMessages().values()) {
            itc.getMessages().put(message.getID(), message);
        }
    }
    ChannelUpdateEvent event = new ChannelUpdateEvent(channel, oldChannel);
    if (channel instanceof IGuildChannel && oldChannel instanceof IGuildChannel) {
        loader.emit(new GuildChannelUpdateEvent((IGuildChannel) channel, (IGuildChannel) oldChannel));
    }
    loader.emit(Events.CHANNEL_UPDATE, event);
    loader.emit(event);
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) IChannel(io.discloader.discloader.entity.channel.IChannel) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent) ChannelUpdateEvent(io.discloader.discloader.common.event.channel.ChannelUpdateEvent) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) IMessage(io.discloader.discloader.entity.message.IMessage) IGuild(io.discloader.discloader.entity.guild.IGuild) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)

Aggregations

ChannelUpdateEvent (io.discloader.discloader.common.event.channel.ChannelUpdateEvent)1 GuildChannelUpdateEvent (io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)1 IChannel (io.discloader.discloader.entity.channel.IChannel)1 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)1 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)1 IGuild (io.discloader.discloader.entity.guild.IGuild)1 IMessage (io.discloader.discloader.entity.message.IMessage)1 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)1