Search in sources :

Example 1 with ChannelType

use of org.javacord.api.entity.channel.ChannelType in project Javacord by BtoBastian.

the class ServerImpl method getOrCreateServerStageVoiceChannel.

/**
 * Gets or creates a server stage voice channel.
 *
 * @param data The json data of the channel.
 * @return The server stage voice channel.
 */
public ServerStageVoiceChannel getOrCreateServerStageVoiceChannel(JsonNode data) {
    long id = Long.parseLong(data.get("id").asText());
    ChannelType type = ChannelType.fromId(data.get("type").asInt());
    synchronized (this) {
        if (type == ChannelType.SERVER_STAGE_VOICE_CHANNEL) {
            return getStageVoiceChannelById(id).orElseGet(() -> new ServerStageVoiceChannelImpl(api, this, data));
        }
    }
    // Invalid channel type
    return null;
}
Also used : ServerStageVoiceChannelImpl(org.javacord.core.entity.channel.ServerStageVoiceChannelImpl) ChannelType(org.javacord.api.entity.channel.ChannelType)

Example 2 with ChannelType

use of org.javacord.api.entity.channel.ChannelType in project Javacord by BtoBastian.

the class ServerImpl method getOrCreateChannelCategory.

/**
 * Gets or creates a channel category.
 *
 * @param data The json data of the channel.
 * @return The server text channel.
 */
public ChannelCategory getOrCreateChannelCategory(JsonNode data) {
    long id = Long.parseLong(data.get("id").asText());
    ChannelType type = ChannelType.fromId(data.get("type").asInt());
    synchronized (this) {
        if (type == ChannelType.CHANNEL_CATEGORY) {
            return getChannelCategoryById(id).orElseGet(() -> new ChannelCategoryImpl(api, this, data));
        }
    }
    // Invalid channel type
    return null;
}
Also used : ChannelCategoryImpl(org.javacord.core.entity.channel.ChannelCategoryImpl) ChannelType(org.javacord.api.entity.channel.ChannelType)

Example 3 with ChannelType

use of org.javacord.api.entity.channel.ChannelType in project Javacord by BtoBastian.

the class ChannelCreateHandler method handle.

@Override
public void handle(JsonNode packet) {
    ChannelType type = ChannelType.fromId(packet.get("type").asInt());
    switch(type) {
        case SERVER_TEXT_CHANNEL:
            handleServerTextChannel(packet);
            break;
        case PRIVATE_CHANNEL:
            handlePrivateChannel(packet);
            break;
        case SERVER_VOICE_CHANNEL:
            handleServerVoiceChannel(packet);
            break;
        case SERVER_STAGE_VOICE_CHANNEL:
            handleServerStageVoiceChannel(packet);
            break;
        case GROUP_CHANNEL:
            handleGroupChannel(packet);
            break;
        case CHANNEL_CATEGORY:
            handleChannelCategory(packet);
            break;
        case SERVER_NEWS_CHANNEL:
            logger.debug("Received CHANNEL_CREATE packet for a news channel. In this Javacord version it is " + "treated as a normal text channel!");
            handleServerTextChannel(packet);
            break;
        case SERVER_STORE_CHANNEL:
            // TODO Handle store channels
            logger.debug("Received CHANNEL_CREATE packet for a store channel. These are not supported in this" + " Javacord version and get ignored!");
            break;
        default:
            logger.warn("Unknown or unexpected channel type. Your Javacord version might be out of date!");
    }
}
Also used : ChannelType(org.javacord.api.entity.channel.ChannelType)

Example 4 with ChannelType

use of org.javacord.api.entity.channel.ChannelType in project Javacord by BtoBastian.

the class ChannelUpdateHandler method handle.

@Override
public void handle(JsonNode packet) {
    ChannelType type = ChannelType.fromId(packet.get("type").asInt());
    switch(type) {
        case SERVER_TEXT_CHANNEL:
            handleServerChannel(packet);
            handleRegularServerChannel(packet);
            handleServerTextChannel(packet);
            break;
        case PRIVATE_CHANNEL:
            handlePrivateChannel(packet);
            break;
        case SERVER_VOICE_CHANNEL:
            handleServerChannel(packet);
            handleRegularServerChannel(packet);
            handleServerVoiceChannel(packet);
            break;
        case SERVER_STAGE_VOICE_CHANNEL:
            handleServerChannel(packet);
            handleRegularServerChannel(packet);
            handleServerVoiceChannel(packet);
            handleServerStageVoiceChannel(packet);
            break;
        case GROUP_CHANNEL:
            handleGroupChannel(packet);
            break;
        case CHANNEL_CATEGORY:
            handleServerChannel(packet);
            handleRegularServerChannel(packet);
            handleChannelCategory(packet);
            break;
        case SERVER_NEWS_CHANNEL:
            logger.debug("Received CHANNEL_UPDATE packet for a news channel. In this Javacord version it is " + "treated as a normal text channel!");
            handleServerChannel(packet);
            handleRegularServerChannel(packet);
            handleServerTextChannel(packet);
            break;
        case SERVER_STORE_CHANNEL:
            // TODO Handle store channels
            logger.debug("Received CHANNEL_UPDATE packet for a store channel. These are not supported in this" + " Javacord version and get ignored!");
            break;
        default:
            logger.warn("Unknown or unexpected channel type. Your Javacord version might be out of date!");
    }
}
Also used : ChannelType(org.javacord.api.entity.channel.ChannelType)

Example 5 with ChannelType

use of org.javacord.api.entity.channel.ChannelType in project Javacord by BtoBastian.

the class ChannelDeleteHandler method handle.

@Override
public void handle(JsonNode packet) {
    ChannelType type = ChannelType.fromId(packet.get("type").asInt());
    switch(type) {
        case SERVER_TEXT_CHANNEL:
            handleServerTextChannel(packet);
            break;
        case PRIVATE_CHANNEL:
            handlePrivateChannel(packet);
            break;
        case SERVER_VOICE_CHANNEL:
            handleServerVoiceChannel(packet);
            break;
        case SERVER_STAGE_VOICE_CHANNEL:
            handleServerStageVoiceChannel(packet);
            break;
        case GROUP_CHANNEL:
            handleGroupChannel(packet);
            break;
        case CHANNEL_CATEGORY:
            handleCategory(packet);
            break;
        case SERVER_NEWS_CHANNEL:
            // TODO Handle server news channel differently
            handleServerTextChannel(packet);
            break;
        case SERVER_STORE_CHANNEL:
            // TODO Handle store channels
            logger.debug("Received CHANNEL_DELETE packet for a store channel. These are not supported in this" + " Javacord version and get ignored!");
            break;
        default:
            logger.warn("Unknown or unexpected channel type. Your Javacord version might be out of date!");
    }
    api.removeChannelFromCache(packet.get("id").asLong());
}
Also used : ChannelType(org.javacord.api.entity.channel.ChannelType)

Aggregations

ChannelType (org.javacord.api.entity.channel.ChannelType)8 ChannelCategoryImpl (org.javacord.core.entity.channel.ChannelCategoryImpl)1 ServerStageVoiceChannelImpl (org.javacord.core.entity.channel.ServerStageVoiceChannelImpl)1 ServerTextChannelImpl (org.javacord.core.entity.channel.ServerTextChannelImpl)1 ServerThreadChannelImpl (org.javacord.core.entity.channel.ServerThreadChannelImpl)1 ServerVoiceChannelImpl (org.javacord.core.entity.channel.ServerVoiceChannelImpl)1