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);
}
}
}
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);
}
}
}
Aggregations