Search in sources :

Example 6 with ChannelType

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

the class ServerImpl method getOrCreateServerTextChannel.

/**
 * Gets or creates a server text channel.
 *
 * @param data The json data of the channel.
 * @return The server text channel.
 */
public ServerTextChannel getOrCreateServerTextChannel(JsonNode data) {
    long id = Long.parseLong(data.get("id").asText());
    ChannelType type = ChannelType.fromId(data.get("type").asInt());
    synchronized (this) {
        switch(type) {
            case SERVER_TEXT_CHANNEL:
            case // TODO Treat news channels differently
            SERVER_NEWS_CHANNEL:
                return getTextChannelById(id).orElseGet(() -> new ServerTextChannelImpl(api, this, data));
            default:
                // Invalid channel type
                return null;
        }
    }
}
Also used : ChannelType(org.javacord.api.entity.channel.ChannelType) ServerTextChannelImpl(org.javacord.core.entity.channel.ServerTextChannelImpl)

Example 7 with ChannelType

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

the class ServerImpl method getOrCreateServerVoiceChannel.

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

Example 8 with ChannelType

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

the class ServerImpl method getOrCreateServerThreadChannel.

/**
 * Gets or creates a server text channel.
 *
 * @param data The json data of the channel.
 * @return The server text channel.
 */
public ServerThreadChannel getOrCreateServerThreadChannel(final JsonNode data) {
    final long id = Long.parseLong(data.get("id").asText());
    final ChannelType type = ChannelType.fromId(data.get("type").asInt());
    synchronized (this) {
        switch(type) {
            case SERVER_PUBLIC_THREAD:
            case SERVER_PRIVATE_THREAD:
            case SERVER_NEWS_THREAD:
                return getThreadChannelById(id).orElseGet(() -> new ServerThreadChannelImpl(api, this, data));
            default:
                // Invalid channel type
                return null;
        }
    }
}
Also used : ServerThreadChannelImpl(org.javacord.core.entity.channel.ServerThreadChannelImpl) 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