Search in sources :

Example 1 with ServerChannelChangeNameEventImpl

use of org.javacord.core.event.channel.server.ServerChannelChangeNameEventImpl in project Javacord by BtoBastian.

the class ThreadUpdateHandler method handleThread.

private void handleThread(final JsonNode jsonChannel) {
    final long channelId = jsonChannel.get("id").asLong();
    final long serverId = jsonChannel.get("guild_id").asLong();
    final ServerImpl server = api.getServerById(serverId).map(ServerImpl.class::cast).orElse(null);
    if (server == null) {
        logger.warn("Unable to find server with id {}", serverId);
        return;
    }
    final ServerThreadChannelImpl thread = (ServerThreadChannelImpl) server.getOrCreateServerThreadChannel(jsonChannel);
    // Handling whether the name has changed
    final String oldName = thread.getName();
    final String newName = jsonChannel.get("name").asText();
    if (!Objects.deepEquals(oldName, newName)) {
        thread.setName(newName);
        final ServerChannelChangeNameEvent event = new ServerChannelChangeNameEventImpl(thread, newName, oldName);
        if (server.isReady()) {
            api.getEventDispatcher().dispatchServerChannelChangeNameEvent((DispatchQueueSelector) thread.getServer(), thread.getServer(), thread, event);
        }
    }
}
Also used : ServerThreadChannelImpl(org.javacord.core.entity.channel.ServerThreadChannelImpl) ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerChannelChangeNameEvent(org.javacord.api.event.channel.server.ServerChannelChangeNameEvent) ServerChannelChangeNameEventImpl(org.javacord.core.event.channel.server.ServerChannelChangeNameEventImpl)

Example 2 with ServerChannelChangeNameEventImpl

use of org.javacord.core.event.channel.server.ServerChannelChangeNameEventImpl in project Javacord by BtoBastian.

the class ChannelUpdateHandler method handleServerChannel.

/**
 * Handles a server channel update.
 *
 * @param jsonChannel The channel data.
 */
private void handleServerChannel(JsonNode jsonChannel) {
    long channelId = jsonChannel.get("id").asLong();
    long guildId = jsonChannel.get("guild_id").asLong();
    ServerImpl server = api.getPossiblyUnreadyServerById(guildId).map(ServerImpl.class::cast).orElse(null);
    if (server == null) {
        return;
    }
    ServerChannelImpl channel = server.getChannelById(channelId).map(ServerChannelImpl.class::cast).orElse(null);
    if (channel == null) {
        return;
    }
    String oldName = channel.getName();
    String newName = jsonChannel.get("name").asText();
    if (!Objects.deepEquals(oldName, newName)) {
        channel.setName(newName);
        ServerChannelChangeNameEvent event = new ServerChannelChangeNameEventImpl(channel, newName, oldName);
        if (server.isReady()) {
            api.getEventDispatcher().dispatchServerChannelChangeNameEvent((DispatchQueueSelector) channel.getServer(), channel.getServer(), channel, event);
        }
    }
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) RegularServerChannelImpl(org.javacord.core.entity.channel.RegularServerChannelImpl) ServerChannelImpl(org.javacord.core.entity.channel.ServerChannelImpl) ServerChannelChangeNameEvent(org.javacord.api.event.channel.server.ServerChannelChangeNameEvent) ServerChannelChangeNameEventImpl(org.javacord.core.event.channel.server.ServerChannelChangeNameEventImpl)

Aggregations

ServerChannelChangeNameEvent (org.javacord.api.event.channel.server.ServerChannelChangeNameEvent)2 ServerImpl (org.javacord.core.entity.server.ServerImpl)2 ServerChannelChangeNameEventImpl (org.javacord.core.event.channel.server.ServerChannelChangeNameEventImpl)2 RegularServerChannelImpl (org.javacord.core.entity.channel.RegularServerChannelImpl)1 ServerChannelImpl (org.javacord.core.entity.channel.ServerChannelImpl)1 ServerThreadChannelImpl (org.javacord.core.entity.channel.ServerThreadChannelImpl)1