Search in sources :

Example 1 with ChannelDeleteEvent

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

the class ChannelDelete 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 channel = null;
    if (data.guild_id != null) {
        guild = EntityRegistry.getGuildByID(data.guild_id);
        channel = EntityRegistry.addChannel(data, loader, guild);
    } else {
        channel = EntityRegistry.addChannel(data, loader);
    }
    switch(channel.getType()) {
        case TEXT:
            guild.getTextChannels().remove(channel.getID());
            break;
        case VOICE:
            guild.getVoiceChannels().remove(channel.getID());
            break;
        default:
            EntityRegistry.removeChannel(channel);
            break;
    }
    ChannelDeleteEvent event = new ChannelDeleteEvent(channel);
    loader.emit(Events.CHANNEL_DELETE, event);
    loader.emit(event);
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) IChannel(io.discloader.discloader.entity.channel.IChannel) ChannelDeleteEvent(io.discloader.discloader.common.event.channel.ChannelDeleteEvent) IGuild(io.discloader.discloader.entity.guild.IGuild)

Aggregations

ChannelDeleteEvent (io.discloader.discloader.common.event.channel.ChannelDeleteEvent)1 IChannel (io.discloader.discloader.entity.channel.IChannel)1 IGuild (io.discloader.discloader.entity.guild.IGuild)1 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)1